Clean Python Solution, TC : O(n*m) , SC : O(n+m)
Approach\n Describe your approach to solving the problem. \n1. We need to take every squares of nums1 and find product pairs in nums2 and viceversa.\n\n2. So we
# Approach\n<!-- Describe your approach to solving the problem. -->\n1. We need to take every squares of nums1 and find product pairs in nums2 and viceversa.\n\n2. So we can take the count of squares in both array to minimise repititive work, like if there are same numbers mutiple times. And save the squares and their count in hashmap sq1 and sq2\n\n3. After that we can take every square from sq1 and find pairs in nums2. The approach came to my mind to minimise this task is the TWO SUM problem ( 1st problem on leetcode ). \n\n4. so if we take one number \'n\' and save the another required number in a hashmap and if that come after, we increment the result variable by number of time it\'s pair occured before multiply by the number of squares present in nums1 ie, sq1[n*n].\n\n5. Then we repeat the task for type 2.\n\n6. Finally returns the result.\n\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n$$O(n*m)$$\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n$$O(n+m)$$\n# Code\n```\nclass Solution:\n    def numTriplets(self, nums1: List[int], nums2: List[int]) -> int:\n        sq1=defaultdict(int)\n        sq2=defaultdict(int)\n        res=0\n\n        #saving the count pf squares\n\n        for n in nums1:\n            sq1[n*n]+=1\n        for n in nums2:\n            sq2[n*n]+=1\n\n        #type 1\n\n        for s in sq1:\n            h2=defaultdict(int)\n            for n in nums2:\n                rem=s%n\n                if not rem:\n                    res+=h2[n]*sq1[s]\n                    h2[s//n]+=1\n\n        #type 2\n\n        for s in sq2:\n            h1=defaultdict(int)\n            for n in nums1:\n                rem=s%n\n                if not rem:\n                    res+=h1[n]*sq2[s]\n                    h1[s//n]+=1\n\n        return res\n```
['Hash Table', 'Counting', 'Python3']