Problem statement

https://binarysearch.com/problems/Equivalent-Product-Pairs/

Solution

Notice that all valuea are unique. Then we can keep counter of all products.

Complexity

It is O(n^2) for time and space.

Code

class Solution:
    def solve(self, A):
        cnt = Counter(x*y for x, y in combinations(A, 2))
        return sum(c * (c - 1) * 4 for c in cnt.values())