Group strings that are anagrams of each other into separate lists.
Given an array of strings, group together the strings that are anagrams. Two strings are anagrams if they contain the same characters with the same frequencies, possibly in a different order.
Return the groups in any order. The order of strings within each group also does not matter.
Input Format
- An array of lowercase strings
strings. - Each string contains only English letters.
Output Format
- Return a list of groups.
- Each group contains all strings from the input that are anagrams of one another.
Constraints
- Strings are non-empty.
- All characters are lowercase English letters.
- The answer may be returned in any order.
Example 1
Input
["eat","tea","tan","ate","nat","bat"]
Output
[["eat","tea","ate"],["tan","nat"],["bat"]]
Explanation
Words with the same multiset of letters are placed in the same group.
Example 2
Input
[""]
Output
[[""]],
Explanation
A single string forms one group by itself.
Show 1 more example
Example 3
Input
["a"]
Output
[["a"]]
Explanation
A single-character string is an anagram only of itself in this input.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.