Group Anagrams Together

Given an array/list of strings STR_LIST, group the anagrams together and return each group as a list of strings. Each group must contain strings that are anagrams of each other.

Example:

STR_LIST = ["abc", "ged", "dge", "bac"]
Output:
[ ["abc", "bac"], ["ged", "dge"] ]
Explanation:

The words "abc" and "bac" are anagrams, so they form one group, and "ged" and "dge" form another group.

Constraints:

  • 1 <= T <= 5
  • 1 <= N <= 1000
  • 1 <= |STR_LIST[i]| <= 100
  • STR_LIST[i] contains only lowercase English letters.
Note:

An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase.

Input:
The first line contains an integer 'T', the number of test cases.
Each test case starts with an integer 'N', the number of strings.
The following line contains 'N' space-separated strings.
Output:
For each test case, print the anagram groups with each group in a separate line.
AnswerBot
4mo

Group anagrams in a list of strings together and return each group as a list of strings.

  • Iterate through the list of strings and sort each string alphabetically to identify anagrams.

  • Use a hashmap to gr...read more

Help your peers!
Select
Add answer anonymously...

Ernst & Young Technology Consultant interview questions & answers

A Technology Consultant was asked 3w agoQ. What are your expectations from this role?
A Technology Consultant was asked Q. How do you detect and handle memory leaks in Node.js?
A Technology Consultant was asked Q. What is cloud computing?

Popular interview questions of Technology Consultant

A Technology Consultant was asked 1mo agoQ1. What are your expectations from this role?
A Technology Consultant was asked Q2. How do you detect and handle memory leaks in Node.js?
A Technology Consultant was asked Q3. What is cloud computing?
Ernst & Young Technology Consultant Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits