Group Anagrams
Part of Practice: Hash Keys & Buckets
You are given an array of strings. Group the strings so that all anagrams of each other end up in the same group, and return the list of groups in any order. (Anagrams are words made of exactly the same letters with the same counts, just rearranged.)
There can be up to 10,000 strings, each up to 100 lowercase English letters, and the empty string counts as a valid string.
Examples
- Input:
- strs = ["eat", "tea", "tan", "ate", "nat", "bat"]
- Output:
- [["eat", "tea", "ate"], ["tan", "nat"], ["bat"]]
eat, tea, and ate all use the letters a, e, t. tan and nat use a, n, t. bat is alone.
- Input:
- strs = [""]
- Output:
- [[""]]
- Input:
- strs = ["a"]
- Output:
- [["a"]]
Hints
One at a time — struggle first, peek second.
Your thinking space — verify on LeetCode, then mark it.