Java | O(N) solution using bitmask
Approach\n1. Iteratre through each word, set the bit corresponding to the index. \n2. Count number of occurences of each bitmask by storing in a map with the bi
# Approach\n1. Iteratre through each word, set the bit corresponding to the index. \n2. Count number of occurences of each bitmask by storing in a map with the bitmask as the key and count as the value. \n3. Finally calculate the number of pairs from the count using the A.P formula \n\nCalculating the number of pairs from the count\n$$pairs = (count * (count-1))/2$$\n\n# Complexity\n- Time complexity: $$O(n)$$\n\n- Space complexity: $$O(n)$$\n\n# Code\n```\nclass Solution {\n    public int similarPairs(String[] words) {\n        var map = new HashMap<Integer, Integer>();\n        for (var word : words) {\n            int bitset = 0;\n            for (int i=0; i<word.length(); i++) {\n                int index = word.charAt(i)-\'a\';\n                bitset |= (1 << index);\n            }\n            map.put(bitset, map.getOrDefault(bitset, 0) + 1);\n        }\n        \n        int pairs = 0;\n        for (var entry: map.entrySet()) {\n            var count = entry.getValue();\n            if (count <= 1) continue;\n            pairs += (count * (count-1)) / 2;\n        }\n        return pairs;\n    }\n}\n```
['Bitmask', 'Java']