Given an array of lowercase strings strs, group together the strings that are anagrams of one another.
Under this judge contract, keep the output deterministic:
Input / output
strs: string[]string[][]Examples
strs = ["eat","tea","tan","ate","nat","bat"] returns [["eat","tea","ate"],["tan","nat"],["bat"]].
The first group is created by "eat", then "tan", then "bat".strs = [""] returns [[""]].
The empty string forms a valid one-word anagram group.strs = ["abc","bca","cab","foo","ofo"] returns [["abc","bca","cab"],["foo","ofo"]].
Each bucket contains exactly the words with matching character counts.Constraints
1 <= strs.length <= 10^40 <= strs[i].length <= 100strs[i] contains only lowercase English lettersEdge cases
Target complexity
O(n * k) time, where k is the maximum word length.O(n * k) space for the hash buckets and stored output.Hints
Follow-up What trade-off do you make if you sort each string to build the key instead of counting letters?