Group Anagram Names
Updated
Problem statement
Given an array of lowercase names names, group names that are anagrams of one another. Two names are anagrams when every letter appears the same number of times in both names.
- Every input occurrence must appear exactly once in the result. Keep duplicate names.
- Order groups by the first appearance of any member of that group in
names. - Within each group, keep names in their original input order.
- Return an empty list when
namesis empty.
Function
groupAnagramNames(names: String[]) → List<List<String>>Examples
Example 1
names = ["amy","may","bob","yma","obb"]return = [["amy","may","yma"],["bob","obb"]]The first group is created by amy. Its later anagrams stay in input order; bob starts the second group.
Example 2
names = ["anna","anan","ann","anna"]return = [["anna","anan","anna"],["ann"]]Repeated names are retained. The three-letter name ann has different character counts and belongs to another group.
Example 3
names = []return = []An empty input produces no groups.
Constraints
0 <= names.length <= 1000.- Each name contains only lowercase English letters and has length from
1to50. - The total number of characters is at most
5000.
More WhatNot Phone Screen questions
- Merge Sorted Squares of Two ArraysPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Adjacent Pair and Run RemovalPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- User Journey PathsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- User Journey Paths from a Log StreamPHONE SCREEN · Seen Nov 2026
- Reachable Exits in an Obstacle GridPHONE SCREEN · Seen Oct 2026
- Palindrome with One DeletionPHONE SCREEN · Seen Oct 2026
- Search a 2D MatrixPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Attraction Route Without Reusing TrailsPHONE SCREEN · Seen Sep 2026
- Earliest Car for Each PassengerPHONE SCREEN · Seen Sep 2026
- Minimum Stores for a Shopping ListPHONE SCREEN · Seen Sep 2026
Similar questions at other companies
- Group AnagramsAmazon Web Services · ONSITE INTERVIEWAmazon Web Services interview questions
- In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
- Longest Consecutive Login StreakAmazon · ONSITE INTERVIEW
- Group AnagramsWorkday · PHONE SCREEN
- Bank Account Balances (Part 2): Monthly ReconciliationStripe · PHONE SCREENStripe interview questions
- Transform Dotted Keys into a Nested MapProofpoint · ONSITE INTERVIEW
- Serialize and Deserialize a String Key-Value StoreByteDance · ONSITE INTERVIEWByteDance interview questions
- Time-Aware Search AutocompleteRoblox · PHONE SCREENRoblox interview questions
- Top Ten Most Frequent Words in a BookRobinhood · PHONE SCREENRobinhood interview questions
- Group AnagramsMicrosoft · ONSITE INTERVIEWMicrosoft interview questions