Given a list of strings strs, place strings that are anagrams into the same group and return those groups.
Two strings qualify as anagrams when each character appears the same number of times in both strings.
n, representing how many strings follow.n lines contains one lowercase English string.To make the result deterministic:
1 <= n <= 1000000 <= len(strs[i]) <= 1001000000.Input:
6
arc
car
care
acre
robed
bored
Output:
[["acre", "care"], ["arc", "car"], ["bored", "robed"]]
The pairs acre/care, arc/car, and bored/robed each have identical character counts, so they form separate groups. Sorting the strings and then the groups produces the displayed order.
Input:
5
listen
silent
enlist
dog
god
Output: [["dog", "god"], ["enlist", "listen", "silent"]]
Here, dog and god are anagrams, while listen, silent, and enlist share the same letters with the same frequencies. The group beginning with dog comes first lexicographically.