CodeOath
← All problems

Group Anagrams

Medium
arraysstringshash-table

Given an array of strings strs, group the anagrams together. Within each group, the strings are sorted alphabetically, and the groups themselves are ordered alphabetically by their (alphabetically smallest) first string.

Example:

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

Constraints:

  • 1 <= strs.length <= 10^4
  • lowercase English letters only