
Asked in Goldman Sachs
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 together in a list of strings.
Iterate through the list of strings and sort each string to group anagrams together.
Use a hashmap to store the sorted string as key and the original string...read more
Help your peers!
Add answer anonymously...
Top Software Developer Intern Interview Questions Asked at Goldman Sachs
Q. Write the code for Merge Sort.
Q. Given a sorted array of integers nums and an integer target, write a function to...read more
Q. Rectangle Area Problem Statement You are provided with a list of rectangles, eac...read more
Interview Questions Asked to Software Developer Intern at Other Companies
Top Skill-Based Questions for Goldman Sachs Software Developer Intern
C++ Interview Questions and Answers
300 Questions
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
Operating Systems Interview Questions and Answers
250 Questions
System Design Interview Questions and Answers
250 Questions
Stay ahead in your career. Get AmbitionBox app


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
AmbitionBox Awards
Get AmbitionBox app

