Python | Instructions to code | Intuitive
\nclass Solution:\n    def numTriplets(self, nums1: List[int], nums2: List[int]) -> int:\n        def is_perf_sqrt(n): \n            """\n            returns bo
```\nclass Solution:\n    def numTriplets(self, nums1: List[int], nums2: List[int]) -> int:\n        def is_perf_sqrt(n): \n            """\n            returns bool if a number is a perfect square\n            like 4, 16, 25 --> True\n            """\n            return int(math.sqrt(n) + 0.5) ** 2 == n\n\n        nums1_cntr, nums2_cntr = Counter(nums1), Counter(nums2)\n\n        s = 0\n        for x, y in itertools.combinations(nums2, 2):\n            if is_perf_sqrt(x * y): \n\t\t\t\t# if product is perfect square, get count of sqrt(of_product)\n\t\t\t\ts += nums1_cntr[math.sqrt(x * y)]\n\t\t\n\t\t# similar vice-versa logic\n        for x, y in itertools.combinations(nums1, 2):\n            if is_perf_sqrt(x * y): s += nums2_cntr[math.sqrt(x * y)]\n\n        return s\n```
[]