Untitled

 avatar
unknown
plain_text
3 months ago
740 B
8
Indexable
class Solution {
public:
    int tupleSameProduct(vector<int>& nums) {
        vector < int > v;

        for(int i=0;i<nums.size();i++) {
            for(int j=i+1;j<nums.size();j++) {
                v.push_back(nums[i]*nums[j]);
            }
        }

        sort(v.begin(),v.end());

        int match = 0, numberOfPairs = 0, numberOfWays = 0;

        for(int i=1;i<v.size();i++) {
            if(v[i] == v[i-1]) {
                match++;
            } else {
                numberOfWays = (match*(match+1))/2;
                numberOfPairs+=numberOfWays;
                match = 0;
            }
        }

        numberOfWays = (match*(match-1))/2;
        numberOfPairs+=numberOfWays;

        return numberOfPairs*8;
    }
};
Editor is loading...
Leave a Comment