Anagrams of a Word in a Word List
Updated
Problem statement
Given a string word and an array of strings dictionary that holds valid English words, return every word in dictionary that is an anagram of word.
An anagram of word is a word made by rearranging all the letters of word: it uses each letter exactly as many times as word does, so it also has the same length. word counts as an anagram of itself, so if word is in dictionary, it is part of the answer.
Return the matching words in the order they appear in dictionary. If no word matches, return an empty array.
Function
findWordAnagrams(word: String, dictionary: String[]) → String[]Examples
Example 1
word = "tops"dictionary = ["post","pots","stop","stops","top","spot","pest"]return = ["post","pots","stop","spot"]"post", "pots", "stop" and "spot" each use the letters t, o, p and s once, like "tops". "stops" and "top" have a different length, and "pest" has an e instead of an o. The four matches keep their order from dictionary.
Example 2
word = "stressed"dictionary = ["desserts","dessert","stresses","stressed"]return = ["desserts","stressed"]"stressed" has three s, two e, one t, one r and one d. "desserts" has the same counts. "dessert" is one letter short, and "stresses" has four s and no d. "stressed" itself is in dictionary, so it is part of the answer.
Example 3
word = "apple"dictionary = ["appeal","pale","leap"]return = []"pale" and "leap" use only some of the letters of "apple", and "appeal" has one letter too many. No word matches, so the answer is an empty array.
Constraints
1 <= dictionary.length <= 1041 <= word.length <= 201 <= dictionary[i].length <= 20wordand everydictionary[i]consist only of lowercase English letters.- All the words in
dictionaryare different.
More Zillow Onsite Interview questions
- Valid ParenthesesPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2025
- Build a Hash TablePHONE SCREEN · ONSITE INTERVIEW · Seen Feb 2023
- Spiral MatrixPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2022
- First Subarray with the Largest SumOA · ONSITE INTERVIEW · Seen Aug 2021
- Count Duplicate CharactersONSITE INTERVIEW · Seen Oct 2020
- Decision Tree Classifier from ScratchONSITE INTERVIEW · Seen Nov 2019
- Find Median from Data StreamPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2018
- LRU CachePHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2016
- Tic-Tac-Toe Winner on a Huge BoardPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2016
- Most Frequent Three-Page SequencesPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2016
Similar questions at other companies
- Shared Courses for Every Pair of StudentsCrunchyroll · PHONE SCREENCrunchyroll interview questions
- Map and Accumulate Learning QueriesPalantir · ONSITE INTERVIEWPalantir interview questions
- Parse and Sort Integer DataLegora · PHONE SCREEN
- Convert an Entry List to a MapEPAM · PHONE SCREENEPAM interview questions
- Compress Consecutive Integer RangesDocuSign · ONSITE INTERVIEWDocuSign interview questions
- Filter Anagrams of a TargetMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Deduplicate Logs: Keep FirstGoogle · ONSITE INTERVIEWGoogle interview questions
- Loyal Customers by Two-Day Product VarietyAmazon · ONSITE INTERVIEW
- Remove Later Anagrams From a ListBloomberg LP · PHONE SCREENBloomberg LP interview questions
- Type-Ahead Prefix MatchesNavan · ONSITE INTERVIEWNavan interview questions