Group Anagrams
Given an array of strings strs, group the strings that are anagrams of one another (same letters with the same multiplicities). Return the groups as a list of lists in any order.
Open official problem prompt ↗Partition the input words into equivalence classes where two words are equivalent if one is a rearrangement of the other.
Sorting scrambled-letter tiles into labeled trays: you first alphabetize each word's tiles to get a tray label, then drop the original word into the tray with that label.
- Input
- strs = ["eat", "tea", "tan", "ate", "nat", "bat"]
- Output
- [["eat", "tea", "ate"], ["tan", "nat"], ["bat"]]
- Why
- eat/tea/ate share letters a,e,t; tan/nat share a,n,t; bat is alone.
1 <= strs.length <= 10^40 <= strs[i].length <= 100strs[i] consists of lowercase English letters