Group Anagrams
Updated
Problem statement
Group the strings in strs so that two strings appear in the same group exactly when they are anagrams.
So that the answer is always the same, sort the strings inside each group and then sort the groups lexicographically by their first string.
Function
groupAnagrams(strs: String[]) → List<List<String>>Examples
Example 1
strs = ["eat","tea","tan","ate","nat","bat"]return = [["ate","eat","tea"],["bat"],["nat","tan"]]eat, tea and ate use the same letters, and so do tan and nat. bat has no partner. After sorting inside each group and then sorting the groups, the result is as shown.
Example 2
strs = [""]return = [[""]]The only string is the empty string, so it forms one group by itself.
Constraints
1 <= strs.length <= 10^4.0 <= strs[i].length <= 100.strs[i]consists of lowercase English letters.
More Bloomberg LP Phone Screen questions
- N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Fewest Coins CombinationPHONE SCREEN · Seen Nov 2026
- Recommend Films from Viewers Who Watched Everything You DidPHONE SCREEN · Seen Nov 2026
- Track New Values in Sorted OrderPHONE SCREEN · Seen Nov 2026
- Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Mutable Stock Price Top KPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Sparse Vector and Matrix OperationsPHONE SCREEN · Seen Oct 2026
- Add Two Numbers IIPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Longest Consecutive Login StreakAmazon · ONSITE INTERVIEW
- Group AnagramsWorkday · PHONE SCREEN
- Group AnagramsMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Group AnagramsEPAM · PHONE SCREENEPAM interview questions
- Find Duplicate Element PairsGoogle · ONSITE INTERVIEWGoogle interview questions
- Find Duplicate File GroupsAnthropic · PHONE SCREENAnthropic interview questions
- Insert an Employee into an Organization HierarchyWaymo · PHONE SCREENWaymo interview questions
- Deep Merge with a Conflict ResolverAutodesk · ONSITE INTERVIEWAutodesk interview questions
- Group Duplicate Files by ContentPostman · ONSITE INTERVIEWPostman interview questions
- Group AnagramsGoldman Sachs · ONSITE INTERVIEWGoldman Sachs interview questions
Interview reports that mention this question
Bloomberg LP interview experiences
- Bloomberg AI-Assisted Coding Round, All Levels: 14 Experiences
- Bloomberg SWE Intern Interview Questions: 68 Questions
- Bloomberg Interview Questions, Level Not Reported: 65 Questions
- Bloomberg Experienced Design & More: 126 Questions (Part 2 of 2)
- Bloomberg Experienced SWE Interviews: 167 Questions (Part 1 of 2)