java simple HashMap
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public int numTriplets(int[] nums1, int[] nums2) {\n        int n1=nums1.length;\n        int n2=nums2.length;\n        HashMap<Long,Long>map1=new HashMap<>();\n        HashMap<Long,Long>map2=new HashMap<>();\n        for(int v:nums1)\n        {\n            long val=(long)((long)v*(long)v);\n            map1.put(val,map1.getOrDefault(val,0L)+1L);\n        }\n        for(int v:nums2)\n        {\n            long val=(long)((long)v*(long)v);\n            map2.put(val,map2.getOrDefault(val,0L)+1L);\n        }\n        \n        HashMap<Long,Long>pmap1=new HashMap<>();\n        HashMap<Long,Long>pmap2=new HashMap<>();\n        for(int i=0;i<n1;i++)\n        {\n            for(int j=i+1;j<n1;j++)\n            {\n                long p=(long)((long)nums1[i]*(long)nums1[j]);\n                pmap1.put(p,pmap1.getOrDefault(p,0L)+1L);\n            }\n        }\n        for(int i=0;i<n2;i++)\n        {\n            for(int j=i+1;j<n2;j++)\n            {\n                long p=(long)((long)nums2[i]*(long)nums2[j]);\n                pmap2.put(p,pmap2.getOrDefault(p,0L)+1L);\n            }\n        }\n        // System.out.println(pmap1);\n        // System.out.println(pmap2);\n        long ans=0;\n        for(long v:map1.keySet())\n        {\n            if(pmap2.containsKey(v))\n            {\n                ans+=(long)(pmap2.get(v)*map1.get(v));\n            }\n        }\n        for(long v:map2.keySet())\n        {\n            if(pmap1.containsKey(v))\n            {\n                ans+=(long)(pmap1.get(v)*map2.get(v));\n            }\n        }\n        return (int)ans;\n    }\n}\n```
['Java']