
In a Meta text-processing pipeline for Feed ranking features, you are given a list of lowercase strings. Group all strings that are anagrams of each other and return the groups.
Two strings are anagrams if they contain the same characters with the same frequencies, possibly in a different order.
Implement a function that takes strs, a list of strings, and returns a list of groups, where each group is a list of strings that are mutual anagrams.
strs: List[str]List[List[str]]The order of groups does not matter. The order of strings within each group does not matter.
Example 1
strs = ["eat", "tea", "tan", "ate", "nat", "bat"][["eat", "tea", "ate"], ["tan", "nat"], ["bat"]]Example 2
strs = [""][[""]]1 <= len(strs) <= 10^40 <= len(strs[i]) <= 100strs[i] contains only lowercase English lettersstrs = ["eat", "tea", "tan", "ate", "nat", "bat"]Output[["eat", "tea", "ate"], ["tan", "nat"], ["bat"]]WhyThe words "eat", "tea", and "ate" share the sorted form "aet". "tan" and "nat" share "ant", while "bat" stands alone.strs = [""]Output[[""]]WhyThe empty string has an empty sorted signature and forms a single group.strs = ["a"]Output[["a"]]WhyA single string is trivially its own anagram group.1 <= len(strs) <= 10^40 <= len(strs[i]) <= 100strs[i] contains only lowercase English lettersOutput group order does not matterOrder of strings within each group does not matterdef group_anagrams(strs):