[Java] Use Hashmap to Maintain Frequencies O(N^2 + M^2)
\n    public int numTriplets(int[] nums1, int[] nums2) {\n        HashMap<Long, Integer> s1 = new HashMap();\n        HashMap<Long, Integer> s2 = new HashMap();
```\n    public int numTriplets(int[] nums1, int[] nums2) {\n        HashMap<Long, Integer> s1 = new HashMap();\n        HashMap<Long, Integer> s2 = 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 cur = (long)nums1[i]*nums1[j];\n                s1.put(cur, s1.getOrDefault(cur, 0)+1);\n            }\n        }\n        for(int i=0; i<n2; i++){\n            for(int j=i+1; j<n2; j++){\n                long cur = (long)nums2[i]*nums2[j];\n                s2.put(cur, s2.getOrDefault(cur, 0)+1);\n            }\n        }\n        int res = 0;\n        for(int num : nums1){\n            res+=s2.getOrDefault((long)num*num, 0);\n        }\n        for(int num : nums2){\n            res+=s1.getOrDefault((long)num*num, 0);\n        }\n        return res;\n    }\n```
[]