1
var tupleSameProduct = function (nums) {
2
let tupleCount = 0;
3
let products = {}; // we'll keep track of how many times we've seen a given product before
4
for (let a = 0; a < nums.length; a++) {
5
for (let b = a + 1; b < nums.length; b++) {
6
let product = nums[a] * nums[b];
7
if (products[product]) {
8
// we've seen at least one other pair of numbers with the same product already
9
tupleCount += 8 * products[product]; // multiply by 8 because for any 4 numbers there are 8 permutations
10
products[product] += 1; // increment the count, if we see this product again there are even more possible tuple combinations
11
} else {
12
products[product] = 1; // mark as seen once
13
}
14
}
15
}
16
return tupleCount;
17
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0