Straightforward O(N^2) Java Solution with 2 HashMaps
\n    public int numTriplets(int[] nums1, int[] nums2) {\n        //hashMap: product -> freq\n        HashMap<Long, Integer> map1 = new HashMap<>();\n        Ha
```\n    public int numTriplets(int[] nums1, int[] nums2) {\n        //hashMap: product -> freq\n        HashMap<Long, Integer> map1 = new HashMap<>();\n        HashMap<Long, Integer> map2 = new HashMap<>();\n        int n1 = nums1.length;\n        int n2 = nums2.length;\n        for(int i=0;i<n1; i++){\n            for(int j=i+1; j<n1; j++){\n                Long prod = (long)nums1[i]*nums1[j];\n                map1.put(prod, map1.getOrDefault(prod, 0) + 1);\n            }\n        }\n        for(int i=0;i<n2; i++){\n            for(int j=i+1; j<n2; j++){\n                Long prod = (long) nums2[i]*nums2[j];\n                map2.put(prod, map2.getOrDefault(prod, 0) + 1);\n            }\n        }\n        //get res\n        int res=0;\n        for(int num : nums1){\n            Long sqr = (long)num*num;\n            res += map2.getOrDefault(sqr, 0);\n        } \n        for(int num : nums2){\n            Long sqr = (long)num*num;\n            res += map1.getOrDefault(sqr, 0);\n        }\n        return res;\n    }\n```
[]