← Practice · Hash map

Group Anagrams Medium

Given an array of strings, group the anagrams together. Groups and the strings inside them may be returned in any order.

Examples

  • ["eat","tea","tan","ate","nat","bat"] -> [["bat"],["nat","tan"],["ate","eat","tea"]]
  • [""] -> [[""]]

Define a function named groupAnagrams in JavaScript.

00:00

JavaScript · Tab indents · Ctrl/⌘+Enter runs the tests