Skip to content
LC-1726 Medium LeetCode

1726. Tuple with Same Product

Read the full problem statement on LeetCode.
Difficulty: medium Acceptance: 70% Topics: Array, Hash Table, Counting
View full problem on LeetCode

Reading material

Reference solution (spoiler · python)
# Time:  O(n^2)
# Space: O(n^2)

import collections


class Solution(object):
    def tupleSameProduct(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        result = 0
        count = collections.Counter()
        for i in xrange(len(nums)):
            for j in xrange(i+1, len(nums)): 
                result += count[nums[i]*nums[j]]
                count[nums[i]*nums[j]] += 1
        return 8*result

Solution from kamyu104/LeetCode-Solutions · MIT