Python3 | Using Counter
For both nums1 and nums2, aggregate all the squares in nums1 and nums2. We will use this to easily track all occurences of nums1[i] * nums1[j]  in nums2 and num
For both nums1 and nums2, aggregate all the squares in nums1 and nums2. We will use this to easily track all occurences of nums1[i] * nums1[j]  in nums2 and nums2[i] * nums2[j] in nums1. Then just use nested loops to generate possible combinations that could be in either frequency table.\n\n\n```\nimport collections\n\nclass Solution:\n    \n    # nums will be where nums[j] and nums[k] come from\n    # Look for nums[j] * nums[k] in counts, if it exists grab count from frequency table "counts"\n    def aggregateType(self, nums, counts):\n        total = 0\n        \n        for i in range(0, len(nums)):\n            for j in range(i + 1, len(nums)):\n                target = nums[i] * nums[j]\n                total += counts[target]\n                \n        return total\n    \n    def numTriplets(self, nums1, nums2):\n        \n        #Build frequency table of the squares you can form from num1 and num2\n        counter1 = collections.Counter([num ** 2 for num in nums1])\n        counter2 = collections.Counter([num ** 2 for num in nums2])\n        \n        return self.aggregateType(nums1, counter2) + self.aggregateType(nums2, counter1)\n```
[]