[Typescript] Bitmasks | Time: O(NM) | Space: O(N)
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\nN is th
# 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**N** is the # of words. **M** is the average word length.\n\n- Time complexity: O(NM)\n\n- Space complexity: O(N)\n\n# Code\n```Typescript\nconst LOWER_A = "a".charCodeAt(0);\nfunction similarPairs(words: string[]): number {\n    const mask2Freqs = new Map<number, number>();\n\n    // Initialize # of pairs to 0\n    let pairs = 0;\n\n    // For each word:\n    for (const word of words) {\n\n        // Convert word to a mask\n        let mask = 0;\n        for (const c of word) {\n            mask |= 1 << (c.charCodeAt(0) - LOWER_A);\n        }\n\n        // Update mask frequency\n        const freq = mask2Freqs.get(mask) ?? 0;\n        mask2Freqs.set(mask, freq + 1);\n\n        // Pair with previous similar words\n        pairs += freq;\n    }\n\n    return pairs;\n};\n```
['Hash Table', 'Bitmask', 'TypeScript', 'JavaScript']