Group Anagrams
Updated
Problem statement
Group the strings in strs so that two strings appear in the same group exactly when they are anagrams.
To make the output the same every time, sort the strings inside each group. Then sort the groups by their first string, in dictionary order.
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 Motive Onsite Interview questions
- Longest Equal-Zero-One SubarrayPHONE SCREEN · ONSITE INTERVIEW · Seen Jan 2026
- Maximum Weighted Sum After Left RotationsONSITE INTERVIEW · Seen Jan 2026
- Valid Parenthesis StringPHONE SCREEN · ONSITE INTERVIEW · Seen Jan 2026
- Best Time to Buy and Sell StockONSITE INTERVIEW · Seen Dec 2025
- Target Triplet SumONSITE INTERVIEW · Seen Dec 2025
- Validate IP AddressONSITE INTERVIEW · Seen Dec 2025
- Generate Palindromic PermutationsONSITE INTERVIEW · Seen Dec 2025
- Minimum Swaps to Group Circular OnesONSITE INTERVIEW · Seen Dec 2025
- Staircase Search In A Sorted MatrixONSITE INTERVIEW · Seen Dec 2025
- Search in Rotated Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2025
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