[Javascript] Bitmasks & Hashmap
Solution: Bitmasks & Hashmap\n\nSince there are only 26 lowercase characters, we can keep track of each word\'s unique characters in a bitmask.\nUse a hashmap t
**Solution: Bitmasks & Hashmap**\n\nSince there are only 26 lowercase characters, we can keep track of each word\'s unique characters in a bitmask.\nUse a hashmap to count the number of occurances of each bitmask.\nFrom the occurances of each bitmask, we can find the number of similar pairs.\n\n`n = number of words`, `m = max(words[i].length)`\nTime Complexity: `O(nm)` 105ms\nSpace Complexity: `O(n)` 44.9MB\n```\nvar similarPairs = function(words) {\n  let count = new Map(), ans = 0;\n  for (let word of words) {\n    let mask = getMask(word);\n    let occurances = count.get(mask) || 0;\n    ans += occurances;\n    count.set(mask, occurances + 1);\n  }\n  return ans;\n};\n\nfunction getMask(word) {\n  let mask = 0;\n  for (let i = 0; i < word.length; i++) {\n    let charcode = word[i].charCodeAt() - 97;\n    mask |= (1 << charcode);\n  }\n  return mask;\n}\n```
['JavaScript']