Facebook Pixel
Group Anagrams
Medium

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

Example:

Input: strs = ["eat","tea","tan","ate","nat","bat"]
Output: [["bat"],["nat","tan"],["ate","eat","tea"]]
Explanation: Words with the same characters (sorted) belong to the same group.
Test Cases

Test Cases

Input
eat tea tan ate nat bat
Expected Output
ate eat tea
bat
nat tan
Step 1
Step 2
Step 3
Step 1: Identify the Pattern
Group Anagrams
Medium

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

Example:

Input: strs = ["eat","tea","tan","ate","nat","bat"]
Output: [["bat"],["nat","tan"],["ate","eat","tea"]]
Explanation: Words with the same characters (sorted) belong to the same group.
Test Cases

Test Cases

Input
eat tea tan ate nat bat
Expected Output
ate eat tea
bat
nat tan
Step 1
Step 2
Step 3
Step 1: Identify the Pattern