Zero To DSAZero To DSA
Privacy Policy
Two Sum (Optimal)Longest Consecutive Sequence

Group Anagrams

medium
Time: O(n * k log k)
Space: O(n * k)

Given an array of strings `strs`, group the anagrams together. An anagram is a word formed by rearranging the letters of another.

Constraints

  • 1 <= strs.length <= 10⁴
  • 0 <= strs[i].length <= 100

Examples

Input: strs = ["eat","tea","tan","ate","nat","bat"]
Output: [["bat"],["nat","tan"],["ate","eat","tea"]]
Input: strs = [""]
Output: [[""]]