Skip to main content

Group Anagrams

MIDDLE
GoogleAmazonFacebook

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 a different word, using all the original letters exactly once.

Example:

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

Examples:

Input 1:{"strs":["eat","tea","tan","ate","nat","bat"]}
Output 1:[["eat","tea","ate"],["tan","nat"],["bat"]]
Input 2:{"strs":[""]}
Output 2:[[""]]

Loading editor...

Run your code to see results

Click the Run button above