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.

Example 1
Inputnums = [2,3,4,6]
Output8
There are 8 valid tuples formed by the pairs (2, 6) and (3, 4) because they have the same product.
Example 2
Inputnums = [1,2,4,5,10]
Output16
There are 16 valid tuples formed by matching equal-product pairs such as (1, 10) with (2, 5) and (2, 10) with (4, 5).

Constraints

  • 1 <= nums.length <= 1000
  • 1 <= nums[i] <= 10^4
  • All elements in nums are distinct.

Asked at 5 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate