Skip to content
Onsite

Group Anagrams

MediumP1Coding

Given an array of strings strs, group the strings that are anagrams of each other. Return the groups in any order, and the strings inside a group in any order.

Example 1

Input
strs = ["eat","tea","tan","ate","nat","bat"]
Output
[["bat"],["nat","tan"],["ate","eat","tea"]]
Why
Group order and order inside groups do not matter.

Example 2

Input
strs = [""]
Output
[[""]]

Example 3

Input
strs = ["a"]
Output
[["a"]]

Constraints

  • 1 <= strs.length <= 10^4
  • 0 <= strs[i].length <= 100
  • strs[i] has lower-case English letters only.

Hints

Run checks the 3 visible tests, Submit all 8.