Here's the solution using sorted keys:
function groupAnagrams(strs)
groups := empty hash map // sorted string -> list of strings
for each str in strs
key := sort characters of str
if key not in groups
groups[key] := empty list
append str to groups[key]
return all values in groups
Time: where is the number of strings and is the maximum string length. Space: .