Arrays & Hashing
LC #49Medium
Group Anagrams
Arrays & Hashing
AmazonMetaGoogleMicrosoftBloombergProblem
Given an array of strings, group the strings that are anagrams of each other and return all groups. Example: ["eat","tea","tan","ate","nat","bat"] → [["eat","tea","ate"],["tan","nat"],["bat"]] — order of groups and within each group doesn't matter.
stringhash-mapsorting
Constraints
- ›1 ≤ strs.length ≤ 10⁴
- ›0 ≤ strs[i].length ≤ 100
- ›strs[i] consists of lowercase English letters
Example
Input
strs = ["eat","tea","tan","ate","nat","bat"]Output
[["bat"],["nat","tan"],["ate","eat","tea"]]Why
eat/tea/ate share the same sorted form "aet"