C++ || Similar to two sum problem with hash map
\n\n# Code\n\nclass Solution {\npublic:\n    int numTriplets(vector<int>& nums1, vector<int>& nums2) {\n        std::unordered_map<int, int> m1, m2;\n\n        
\n\n# Code\n```\nclass Solution {\npublic:\n    int numTriplets(vector<int>& nums1, vector<int>& nums2) {\n        std::unordered_map<int, int> m1, m2;\n\n        for(int i : nums1)\n            m1[i]++;\n        \n        for(int i : nums2)\n            m2[i]++;\n\n        int ans = 0;\n        for(const auto& [k1, v1] : m1)\n        {\n            long long x = (long long)k1 * k1;\n            int cnt = 0;\n            for(const auto& [k2, v2] : m2)\n            {\n                if(x % k2 == 0 && m2.count(x / k2))\n                {\n                    int y = m2[x / k2];\n                    if(k2 == x / k2)\n                    {\n                        ans +=v1 * ((y * (y - 1)) / 2);\n                    } else \n                    {\n                        cnt +=v1 * v2 * y;\n                    }\n                }\n            }\n            cnt /= 2;\n            ans += cnt;\n        }\n\n\n        for(const auto& [k1, v1] : m2)\n        {\n            long long x = (long long)k1 * k1;\n            int cnt = 0;\n            for(const auto& [k2, v2] : m1)\n            {\n                if(x % k2 == 0 && m1.count(x / k2))\n                {\n                    int y = m1[x / k2];\n                    if(k2 == x / k2)\n                    {\n                        ans += v1 * ((y * (y - 1)) / 2);\n                    } else \n                    {\n                        cnt +=v1 * v2 * y;\n                    }\n                }\n            }\n            cnt /= 2;\n            ans += cnt;\n        }\n\n\n        return ans;\n    }\n};\n```
['C++']