Tuple with Same Product

Given an array `nums` of **distinct** positive integers, return the number of tuples `(a, b, c, d)` such that `a * b = c * d`, where `a`, `b`, `c` and `d` are elements of `nums` and `a != b != c != d` (all four are different elements).

30:00

Tuple with Same Product
medium
Free written solution
Topics
Companies

Given an array nums of distinct positive integers, return the number of tuples (a, b, c, d) such that a * b = c * d, where a, b, c and d are elements of nums and a != b != c != d (all four are different elements).

Example 1:
Input: {"nums":[2,3,4,6]}
Output: 8
Constraints:
  • 1≤nums.length≤10001 \leq \text{nums.length} \leq 1000

  • 1≤nums[i]≤1041 \leq \text{nums}[i] \leq 10^4

  • All elements in nums are distinct.

Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result

Run code to see results.

Input
arr ={"nums":[2,3,4,6]}

Every pair (a, b) has a product. Two pairs with the same product make 8 tuples, so group the 6 pairs by product.

tuples

0

pairs seen

0/6

products

0

nums

2
3
4
6

buckets by product

empty

Variables
VariableValue
result0
pairs6
DepthFunction Call
Stack empty
0/16