Map/Hash Table Solution in TS/JS
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \nPrecalculated all the s
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nPrecalculated all the squared values and getting their frequencies. Then using two pointers iterated through both arrays checking for type 1 and type 2 and added the frequency count to the result value. If it returned undefined, it doesn\'t exist in the map. \n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n$$O(n^2)$$\n\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n$$O(n)$$\n\n# Code\n```\nfunction numTriplets(nums1: number[], nums2: number[]): number {\n    //type1\n    const map1 = new Map();\n    nums1.forEach(key => {\n        let squared = Math.pow(key,2);\n        if (!map1.has(squared)){\n            map1.set(squared,1);\n        } else {\n            map1.set(squared, map1.get(squared) + 1);\n        }\n    });\n    //type 2\n    const map2 = new Map();\n    nums2.forEach(key => {\n        let squared = Math.pow(key,2);\n        if (!map2.has(squared)){\n            map2.set(squared,1);\n        } else {\n            map2.set(squared, map2.get(squared) + 1);\n        }\n    });\n    \n    let count = 0;\n    for (let i = 0; i < nums1.length; i++){\n        for (let j = 0; j < nums1.length; j++){\n            if (i < j){\n                let value = nums1[i] * nums1[j];\n                if (map2.get(value) != undefined){\n                    count += map2.get(value);\n                }\n            }\n        }\n    }\n\n    for (let i = 0; i < nums2.length; i++){\n        for (let j = 0; j < nums2.length; j++){\n            if (i < j){\n                let value = nums2[i] * nums2[j];\n                if (map1.get(value) != undefined){\n                    count += map1.get(value);\n                }\n            }\n        }\n    }\n    return count;\n};\n```
['Array', 'Hash Table', 'Ordered Map', 'TypeScript']