Add and Search Words With Wildcards
Updated
Problem statement
Build a word dictionary that supports two calls, starting empty:
add(word): storeword.search(pattern): returntrueif some stored word matchespattern. A pattern matches a word when both have the same length and, at every position, the pattern has either the same letter or a dot'.', which stands for any one letter.
You get the calls in order: operations[i] is "add" or "search" and words[i] is its word or pattern. Return the results of the search calls, in order. A search only sees words added before it.
Function
runWordDictionary(operations: String[], words: String[]) → boolean[]Examples
Example 1
operations = ["add","add","search","search","search","search"]words = ["code","cove","co.e","c...","cod","..ve."]return = [true,true,false,false]co.e matches both code and cove, and c... matches any four-letter word starting with c. cod is only the start of a stored word, so it does not match, and ..ve. has five characters while every stored word has four.
Example 2
operations = ["search","add","search"]words = ["a","a","."]return = [false,true]The first search runs before anything is stored, so it is false. After a is added, . matches it.
Example 3
operations = ["add","add","add","search","search"]words = ["bat","bad","bed","b.d","..t"]return = [true,true]b.d matches bad and bed; ..t matches bat.
Constraints
1 <= operations.length <= 3000andwords.length == operations.length- Each
operations[i]is"add"or"search", and at least one is"search" 1 <= words[i].length <= 20- For
"add",words[i]has only lowercase English letters; for"search", it has lowercase letters and'.', with at most3dots
More Adobe Phone Screen questions
- Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
- All Elements of Two BSTs in OrderPHONE SCREEN · Seen Aug 2026
- Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
- Binary Tree Level-Order Traversal by LevelsPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2026
- Count Occurrences in a Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
- Count Pairs with Absolute Difference KPHONE SCREEN · Seen Jul 2026
- Count Subsets with Sum KPHONE SCREEN · Seen Jul 2026
- Numbers with Exactly Three DivisorsPHONE SCREEN · Seen Jul 2026
- Sum of Even Nodes on a Path in a Numbered Binary TreePHONE SCREEN · Seen Jul 2026
- Largest Value in Every Sliding WindowPHONE SCREEN · Seen Jul 2026
Similar questions at other companies
- Word Dictionary with WildcardsDatadog · PHONE SCREENDatadog interview questions
- Word Dictionary with Wildcard FindAmazon · ONSITE INTERVIEW
- Design File SystemGoogle · PHONE SCREENGoogle interview questions
- Prefix Word DictionaryBloomberg LP · PHONE SCREENBloomberg LP interview questions
- Implement TrieOptiver · PHONE SCREENOptiver interview questions
- Design Search Autocomplete SystemRoblox · PHONE SCREEN · ONSITE INTERVIEWRoblox interview questions
- Spreadsheet With Dependent CellsCharacter.AI · PHONE SCREEN
- Evaluate Live Spreadsheet ExpressionsStrala · PHONE SCREEN
- Serialize and Deserialize an N-Ary TreeUber · ONSITE INTERVIEWUber interview questions
- Implement a TrieMicrosoft · ONSITE INTERVIEWMicrosoft interview questions