O(nk) Time O(n) Space
Intuition\nA couple potential solutions that came to mind:\n1. Same concept as Valid Anagram. You can see my solution here.\n    - Admittedly, this felt like a 
# Intuition\nA couple potential solutions that came to mind:\n1. Same concept as [Valid Anagram](https://leetcode.com/problems/valid-anagram). You can see my solution [here](https://leetcode.com/problems/valid-anagram/solutions/2881883/o-n-time-o-26-o-1-space/).\n    - Admittedly, this felt like a performance problem after we mapped every string to it\'s int[] of occurrences\n2. Sort each string and compare if the sorted string has occurred before\n\nWent with the second approach. Also, easier to code up in interview. Initially, I went with the standard string sort that I know of:\n```\nprivate string Sort(string s) {\n    char[] input = s.ToArray();\n    Array.Sort(input);\n    return new string(input);\n}\n```\n\nHowever, we can improve on this by using counting sort since we are limited to 26 potential characters in the lowercase english alphabet.\n\n# Approach\n1. Sort each string\n2. Check in hashmap if we have seen the sorted version of the string before\n    1. If we have, add the original string to the value of the hashmap\n    2. If we haven\'t, add the original string to a new entry in the hashmap\n\n# Complexity\n- Time complexity:\n$$O(nk)$$, where $$n$$ is the length of $$strs$$ and $$k$$ is the length of the longest string in $$strs$$. Our counting sort algorithm uses $$O(26)$$ space and runs in $$O(k+26)$$~$$O(k)$$ time\n\n- Space complexity:\n$$O(n)$$\n\n# Code\n```\npublic class Solution {\n    public IList<IList<string>> GroupAnagrams(string[] strs) {\n        if (strs.Length == 0) {\n            return new List<IList<string>>();\n        }\n\n        Dictionary<string, List<string>> anagrams = new Dictionary<string, List<string>>();\n\n        foreach (string str in strs) {\n            string sortedStr = CountSort(str);\n            if (!anagrams.ContainsKey(sortedStr)) {\n                anagrams.Add(sortedStr, new List<string>());\n            }\n\n            anagrams[sortedStr].Add(str);\n        }\n\n        IList<IList<string>> result = new List<IList<string>>();\n        foreach (KeyValuePair<string, List<string>> kvp in anagrams) {\n            result.Add(kvp.Value);\n        }\n        return result;\n    }\n\n    private string CountSort(string s) {\n        int[] counts = new int[26];\n        foreach (char c in s) {\n            counts[c - \'a\'] += 1;\n        }\n\n        StringBuilder builder = new StringBuilder();\n        for (int i = 0; i < counts.Length; i++) {\n            if (counts[i] > 0) {\n                builder.Append((char)(\'a\' + i), counts[i]);\n            }\n        }\n\n        return builder.ToString();\n    }\n}\n```
['C#']