STL Set to find similar pairs [C++]
\n\n# Approach\n Describe your approach to solving the problem. \n- We use STL unordered_set to find similar strings and store the frequency in an unordered_map
\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n- We use STL `unordered_set` to find similar strings and store the frequency in an `unordered_map`.\n- Keep in mind we should sort the string to handle similar strings. (i.e., `abc` and `cab`)\n- Finding the pair is quite simple after this. TLDR; The formula is `n(n-1)/2` where n is the number of items in the list.\n\n\n\n# Code\n```\nclass Solution {\npublic:\n    int similarPairs(vector<string>& arr) {\n        unordered_map<string, int> c;\n\n        for (auto& str: arr) {\n            unordered_set<char> s(str.begin(), str.end());\n            string t(s.begin(), s.end());\n            sort(t.begin(), t.end());\n            c[t]++;\n        }\n\n        int ans = 0;\n        for (auto& it: c) {\n            int p = it.second;\n            ans += (p * (p-1))/2;\n        }\n\n        return ans;\n    }\n};\n```
['C++']