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.
strings.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.
Example 3
Input
["a"]
Output
[["a"]]
Explanation
A single-character string is an anagram only of itself in this input.
Premium problem context
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.