Group Anagrams

Medium

Given an array of strings strs, group the anagrams together. You can return the answer in any order.

An anagram is a word formed by rearranging the letters of another word, using all the original letters exactly once.

Example 1

groupAnagrams()
Input
strs = ["eat","tea","tan","ate","nat","bat"]
Output
[["bat"],["nat","tan"],["ate","eat","tea"]]

Example 2

groupAnagrams()
Input
strs = [""]
Output
[[""]]
Constraints
1 <= strs.length <= 10^4
0 <= strs[i].length <= 100
strs[i] consists of lowercase English letters.

Topics

StringsHash TableSorting

Implement groupAnagrams in the editor and return the answer — printing it is never graded.