Easy Java Solution Using 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[] arr1, int[] arr2) {\n        int n1 = arr1.length;\n        int n2 = arr2.length;\n\n        HashMap<Long,Integer> hp1 = new HashMap<>();\n        HashMap<Long,Integer> hp2 = new HashMap<>();\n\n        for(int i=0; i<n1; i++){\n            long a = (long)arr1[i]*(long)arr1[i];\n            if(hp1.containsKey(a)) hp1.put(a,hp1.get(a)+1);\n            else hp1.put(a,1);\n        }\n\n        for(int i=0; i<n2; i++){\n            long a = (long)arr2[i]*(long)arr2[i];\n            if(hp2.containsKey(a)) hp2.put(a,hp2.get(a)+1);\n            else hp2.put(a,1);\n        }\n\n\n        int ans = 0;\n\n        for(int i=0; i<n1; i++){\n            for(int j=i+1; j<n1; j++){\n                long a = (long)arr1[i]*(long)arr1[j];\n                if(hp2.containsKey(a)){\n                    ans=ans+hp2.get(a);\n                }\n            }\n        }\n\n        for(int i=0; i<n2; i++){\n            for(int j=i+1; j<n2; j++){\n                long a = (long)arr2[i]*(long)arr2[j];\n                if(hp1.containsKey(a)){\n                    ans=ans+hp1.get(a);\n                }\n            }\n        }\n\n        return ans;\n    }\n}\n```
['Java']