Skip to main content

Group Anagrams

MediumPremium

Given a list of strings, group the anagrams together and return a list of these groups in any order.

Two strings are anagrams if you can rearrange the letters of one to form the other, without adding or losing any letters.

Examples

s: ["eat", "tea", "tan", "ate", "nat", "bat"] output: [["eat", "tea", "ate"], ["tan", "nat"], ["bat"]] s: ["listen", "silent", "enlist", "google", "gooegl"] output: [["listen", "silent", "enlist"], ["google", "gooegl"]] s:[""] output: [""] s: ["p"] output: ["p"]