EASY CPP MAPPING
Intuition\nThe problem requires finding the number of triplets that satisfy either Type 1 or Type 2 conditions. Type 1 triplets have the property that nums1[i]^
# Intuition\nThe problem requires finding the number of triplets that satisfy either Type 1 or Type 2 conditions. Type 1 triplets have the property that `nums1[i]^2` is equal to `nums2[j] * nums2[k]`, and Type 2 triplets have the property that `nums2[i]^2` is equal to `nums1[j] * nums1[k]`.\n\n# Approach\nTo solve this problem, we can iterate through both arrays and check for the conditions for Type 1 and Type 2 triplets.\n\n1. For each element in `nums1`, calculate `k` as the square of that element.\n2. Create an unordered map `mp` to store the counts of elements in `nums2`.\n3. Iterate through `nums2` and check if `k` is divisible by the current element `j`.\n   - If it is divisible, calculate `d` as `k/j`.\n   - Check if `d` is present in the map. If it is, increment the count `cnt` by the value associated with `d` in the map.\n   - Update the count of the current element `j` in the map.\n4. Repeat the same process for `nums2` and `nums1` to handle Type 2 triplets.\n\nAfter both iterations, `cnt` will contain the total count of valid triplets.\n\n# Complexity\n- Time complexity: O(N*M), where N is the length of `nums1` and M is the length of `nums2`. We iterate through both arrays once.\n- Space complexity: O(M) for the unordered map to store counts of elements in `nums2`.\n\n# Code\n```cpp\nclass Solution {\npublic:\n    int numTriplets(vector<int>& nums1, vector<int>& nums2) {\n        int cnt = 0;\n        for (long long i : nums1) {\n            unordered_map<long long, long long> mp;\n            long long k = i * i;\n            for (auto j : nums2) {\n                if (k % j == 0) {\n                    long long d = k / j;\n                    cnt += mp[d];\n                }\n                mp[j]++;\n            }\n        }\n        for (long long i : nums2) {\n            unordered_map<long long, long long> mp;\n            long long k = i * i;\n            for (auto j : nums1) {\n                if (k % j == 0) {\n                    long long d = k / j;\n                    cnt += mp[d];\n                }\n                mp[j]++;\n            }\n        }\n        return cnt;\n    }\n};\n```\n\nThis code correctly counts the number of valid Type 1 and Type 2 triplets and returns the total count.
['C++']