Python3 (and C++, Java)   || set, sort, tuple, Counter   ||   T/S: 92% / 99%
Here\'s the plan:\n\n1. We map each string to its set of characters.\n\n2. We map the set to a sorted list. Any two of theses lists are equal if and only if the
Here\'s the plan:\n\n1. We map each string to its set of characters.\n\n2. We map the set to a sorted list. Any two of theses lists are equal if and only if the original strings are *similar*.\n3. W map the sorted lists to tuples so they are *hashable*.\n4. We determine `c`,  a Counter of the tuples.\n4. We use `c` to count the similar pairs. \n\n```Python3 []\nclass Solution:\n    def similarPairs(self, words: List[str]) -> int:\n\n        words = [set   (w) for w in words]          # <\u2013\u2013 1)\n        words = [sorted(w) for w in words]          # <\u2013\u2013 2)\n        words = [tuple (w) for w in words]          # <\u2013\u2013 3)\n\n        c = Counter(words)                          # <\u2013\u2013 4)\n        \n        return  sum(n*(n-1) for n in c.values())//2 # <\u2013\u2013 5)\n```\n```C++ []\nclass Solution {\npublic:\n    int similarPairs(vector<string>& words) {\n        unordered_map<string, int> c;\n\n        for (string& word : words) {\n            set<char> unique_chars(word.begin(), word.end());  // Step 1\n            string sorted_word(unique_chars.begin(), unique_chars.end());  // Step 2\n            c[sorted_word]++;}  // Step 4\n\n        int ans = 0;\n        for (const auto& pair : c) {\n            int n = pair.second;\n            ans += n * (n - 1) / 2;}  // Count pairs\n\n        return ans;}};\n```\n```Java []\nimport java.util.*;\n\nclass Solution {\n    public int similarPairs(String[] words) {\n        Map<String, Integer> c = new HashMap<>();\n\n        for (String word : words) {\n            Set<Character> uniqueChars = new HashSet<>();  // Step 1\n            for (char ch : word.toCharArray()) {\n                uniqueChars.add(ch);\n            }\n            List<Character> sortedList = new ArrayList<>(uniqueChars);  // Step 2\n            Collections.sort(sortedList);\n            StringBuilder sortedWord = new StringBuilder();  \n            for (char ch : sortedList) sortedWord.append(ch);\n            c.put(sortedWord.toString(), c.getOrDefault(sortedWord.toString(), 0) + 1);  // Step 4\n        }\n\n        int ans = 0;\n        for (int n : c.values()) {\n            ans += n * (n - 1) / 2;  // Step 5\n        }\n\n        return ans;\n    }\n}\n```\nA one-liner in Python3:\n```Python3 []\nclass Solution:\n    def similarPairs(self, words: List[str]) -> int:\n\n        return  sum(n*(n-1) for n in Counter([tuple(sorted(set(w)))\n                                         for w in words]).values())//2\n```\n\n[https://leetcode.com/problems/count-pairs-of-similar-strings/submissions/918995318/](https://leetcode.com/problems/count-pairs-of-similar-strings/submissions/918995318/)\n\nI could be wrong, but I think that time complexity is *O*(*NK* log *K*) and space complexity is *O*(*NK*), in which *N* ~ `len(words)` and *N* ~ *maxLength(words)*.\n
['C++', 'Java', 'Python3']