Skip to main content
LeetCode 1726, Medium. Topics: Array, Hash Table, Counting. View on LeetCode. Generate this problem as a practice environment: tested reference solution, 36 parametrized pytest cases, and a playground notebook:

Problem

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.

Examples

Constraints

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

Solution

Reference implementation from solution.py on GitHub, full suite in test_solution.py:

Complexity

Tags

NeetCode All.
Last modified on September 7, 2026