Bitmask
Since there are up to 26 letters, we use a bitmask to represent a string. Each bitmask, therefore, represents a group of similar strings.\n\nWe use a hash map t
Since there are up to 26 letters, we use a bitmask to represent a string. Each bitmask, therefore, represents a group of similar strings.\n\nWe use a hash map to count similar strings in each bitmask group.\n\nIf we have `n` strings in a group, we can form `n * (n - 1) / 2` pairs.\n\n> Or, we can just add existing number of similar strings to the result when we found another one.\n\n## No Raw Loops Version\n**C++**\n```cpp\nint similarPairs(vector<string>& words) {\n    unordered_map<int, int> m;\n    return accumulate(begin(words), end(words), 0, [&](int cnt, const auto &w){\n        return cnt + m[accumulate(begin(w), end(w), 0, [](int res, char ch) {\n            return res | (1 << (ch - \'a\')); })]++;\n    });\n}\n```\n\n## Raw Loops Version\n**C++**\n```cpp\nint similarPairs(vector<string>& words) {\n    unordered_map<int, int> m;\n    int res = 0;\n    for (const auto &w : words) {\n        int bits = 0;\n        for (auto ch : w)\n            bits |= (1 << (ch - \'a\'));\n        res += m[bits]++;\n    }\n}\n```
[]