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 every solution gives the same answer, sort the strings inside each group. Then sort the groups in dictionary order 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"]]Example 2
strs = [""]return = [[""]]Constraints
1 <= strs.length <= 10^4.0 <= strs[i].length <= 100.strs[i]consists of lowercase English letters.
More Goldman Sachs Onsite Interview questions
- Knight Probability in ChessboardONSITE INTERVIEW · Seen Nov 2026
- Best Average Student ScorePHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Meeting RoomsPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Minimum Meeting Rooms Without a Sweep LineONSITE INTERVIEW · Seen Oct 2026
- First Non-Repeating CharacterPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Root of the Largest TreePHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Dungeon HealthONSITE INTERVIEW · Seen Sep 2026
- Insert, Delete, And Get Random In Constant TimeONSITE INTERVIEW · Seen Sep 2026
- Least Recently Used CacheONSITE INTERVIEW · Seen Sep 2026
- Staircase Search In A Sorted MatrixONSITE INTERVIEW · Seen Sep 2026
Similar questions at other companies
- Group AnagramsAmazon Web Services · ONSITE INTERVIEW
- Longest Consecutive Login StreakAmazon · ONSITE INTERVIEW
- Group AnagramsMicrosoft · ONSITE INTERVIEW
- Find Duplicate Element PairsGoogle · ONSITE INTERVIEW
- Deep Merge with a Conflict ResolverAutodesk · ONSITE INTERVIEW
- Group Duplicate Files by ContentPostman · ONSITE INTERVIEW
- Group AnagramsMotive · PHONE SCREEN · ONSITE INTERVIEW
- Group AnagramsBloomberg LP · PHONE SCREEN · ONSITE INTERVIEW
- Group AnagramsExpedia · ONSITE INTERVIEW
- Group AnagramsAkuna Capital · ONSITE INTERVIEW