C++ | Group Anagrams | Sorting and Hashmap
Bookmarks for LeetCode -- Try Marcam Now!\n\nUsing Sorting - Sort every string and push in appropriate bucket\n Time Complexcity : O(n.klog(k)) where k is the l
# **Bookmarks for LeetCode -- Try [Marcam](https://marcam.vercel.app/) Now!**\n\n**Using Sorting - Sort every string and push in appropriate bucket**\n* **Time Complexcity : `O(n.klog(k))`** *where **k** is the length of string and **n** is total no. of strings*\n* **Space Complexcity : `O(n)`** *if none of the strings are anagram*\n```\nclass Solution {\npublic:\n    vector<vector<string>> groupAnagrams(vector<string>& strs) {\n        vector<vector<string>> ans;\n        unordered_map<string, vector<string>> sorted;\n        \n        for(int i = 0; i < strs.size(); i++){\n            string temp = strs[i];\n            sort(strs[i].begin(), strs[i].end());\n            sorted[strs[i]].push_back(temp);\n        }\n        \n        for(auto it = sorted.begin(); it != sorted.end(); it++){\n            ans.push_back(it->second);\n        }\n        \n        return ans;\n    }\n};\n```
['C', 'Sorting', 'C++']