1
class Solution {
2
public:
3
int tupleSameProduct(vector<int> &nums) {
4
int n = nums.size();
5
unordered_map<int, int> map;
6
int res = 0;
7
for (int i = 0; i < n; i++) {
8
for (int j = i + 1; j < n; j++) {
9
int prod = nums[i] * nums[j];
10
map[prod]++; // store product of each possible pair
11
}
12
}
13
for (pair<int, int> m : map) {
14
int n = m.second;
15
res += (n * (n - 1)) / 2; // no. of tuple
16
}
17
return res * 8; // Every tuple has 8 permutations
18
}
19
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0