[Python3] frequency table
\n\nclass Solution:\n    def numTriplets(self, nums1: List[int], nums2: List[int]) -> int:\n        cnt1, cnt2 = Counter(nums1), Counter(nums2)\n        \n     
\n```\nclass Solution:\n    def numTriplets(self, nums1: List[int], nums2: List[int]) -> int:\n        cnt1, cnt2 = Counter(nums1), Counter(nums2)\n        \n        def fn(x, y, freq): \n            """Return count of triplet of nums[i]**2 = nums[j]*nums[k]."""\n            ans = 0\n            for xx in x: \n                xx *= xx\n                ans += sum(freq[xx//yy] - (yy == xx//yy) for yy in y if not xx%yy and xx//yy in freq)\n            return ans//2\n\n        return fn(nums1, nums2, cnt2) + fn(nums2, nums1, cnt1)\n```
['Python3']