Group Anagrams
Problem statement
Group the strings in strs so that two strings appear in the same group exactly when they are anagrams.
For this exercise, assume every string contains only lowercase English letters. Do not sort the characters of a string to determine its group. Build a fixed 26-entry character-count vector and use that vector as the grouping key.
Sorting is permitted only to format the completed groups: sort the strings inside each group, then sort the groups lexicographically by their first string. Return those groups in that deterministic order.
Function
groupAnagrams(strs: String[]) → String[][]Examples
Example 1
strs = ["eat","tea","tan","ate","nat","bat"]return = [["ate","eat","tea"],["bat"],["nat","tan"]]Example 2
strs = [""]return = [[""]]Source note: Source images are source-neutral excerpts of author-reported interview prompts.