Remove Duplicate Anagrams
Updated
Problem statement
You are given an array of strings called words. Remove every word that is an anagram of any earlier word, even if the two words are not next to each other. Keep the first original word from each anagram group.
Two words are anagrams if each letter appears the same number of times in both words. The letters can be in a different order. Identical words are also anagrams.
In this exercise, every word is nonempty and contains only lowercase English letters. After choosing the first word from each group, sort those original words in alphabetical order and return them. Return an empty array for an empty input.
Function
removeDuplicateAnagrams(words: String[]) → String[]Examples
Example 1
words = ["code","edoc","doce","ant"]return = ["ant","code"]This example keeps code from the first three words and retains ant. Sorting the retained representatives gives ant, code.
Example 2
words = ["bca","cat","abc","tac","cab"]return = ["bca","cat"]bca is the first representative of its group; cat starts another group. The later anagrams are removed. Do not replace bca with the lexicographically smaller abc.
Example 3
words = ["a","aa","a","aaa","aa"]return = ["a","aa","aaa"]Letter multiplicities matter. The words with one, two and three copies of a form different groups; exact duplicates are removed.
Constraints
- For this exercise, assume
0 <= words.length <= 10^4,1 <= words[i].length <= 100, and the total number of input characters is at most2 * 10^5.
More Vanguard Online Assessment questions
- Two SumOA · Seen Sep 2026
- Valid ParenthesesOA · Seen Sep 2026
- Are They PangramsOA · Seen Nov 2025
- Missing WordsOA · Seen Nov 2025
- Spam DetectionOA · Seen Nov 2025
- Binge WatchingOA · Seen Jan 2023
- Minimum Moves Around a Circular ArrayOA · Seen Aug 2022
- Maximum Occurring CharacterOA · Seen Mar 2022
- Picking TicketsOA · Seen Mar 2022
- Tool List: Two Smallest ValuesOA · Seen Nov 2021
Similar questions at other companies
- Count User Mentions in Chat MessagesRamp · OARamp interview questions
- Blood Type Inheritance: Possible Parent GenotypesAbridge · OAAbridge interview questions
- Count Repeated Request IDs (Data Science OA)McKinsey & Company · OAMcKinsey & Company interview questions
- Flat JSON Value DifferencesChubb · OAChubb interview questions
- Get Search ResultsJP Morgan Chase · OAJP Morgan Chase interview questions
- Lexicographic Word FrequenciesUpstart · OAUpstart interview questions
- Email Log Processing, Grouping, and SortingStripe · OAStripe interview questions
- Most Frequent CharacterMicrosoft · OAMicrosoft interview questions
- Get Maximum Information GainAmazon · OA
- Better CompressionGoldman Sachs · OAGoldman Sachs interview questions