Sale
Summer Offer: $190/yr $99/yr
00 : 00 : 00 : 00
Get this deal
Backend Engineer Senior programming

Given an array of strings, write a function to group anagrams together. An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once. Your task is to return a list of groups, where each group contains all the anagrams from the input array.


Constraints:


  • 1 <= strs.length <= 1000

  • 0 <= strs[i].length <= 100

  • The input contains only lowercase alphabets.


Examples:


1. Input: strs = ["eat","tea","tan","ate","nat","bat"]
Output: [["bat"],["nat","tan"],["ate","eat","tea"]]
2. Input: strs = [""]
Output: [[""]]
Suggested Answer

Trusted by 100+ professionals preparing for interviews

Trusted by 100+ professionals 50+ Company Question Banks 5+ Supported Languages

Practice More Questions Like This

Generate unlimited interview questions with structured answers, code runner, and AI-powered walkthroughs.

Get Started Free
Link copied to clipboard