Implement Trie search with wildcard matching
Problem Description
Design and implement a text dictionary using a Trie data structure.
The dictionary must support two primary operations:
addWord(word): Inserts a given lowercase English word into the dictionary.search(pattern): Returnstrueif any previously added word matches the providedpattern. Thepatternmay include the wildcard character.which matches exactly one lowercase English letter. All other characters in the pattern must match themselves exactly.
Inputs/Outputs
Candidates should implement a class containing these two methods, or provide functions capable of processing a sequence of such operations.
Constraints
- The total number of
addWordandsearchoperations will be up to approximately 10^5. - The length of any
wordorpatternwill be up to approximately 10^3 characters. - The solution must be implemented in C++.
AI interview prep
Core dilemma
Balancing the inherent efficiency of a Trie for prefix matching with the exponential branching complexity introduced by wildcard characters during search operations.
2 tradeoffs and 2 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Implement Trie search with wildcard matching
Problem Description
Design and implement a text dictionary using a Trie data structure.
The dictionary must support two primary operations:
addWord(word): Inserts a given lowercase English word into the dictionary.search(pattern): Returnstrueif any previously added word matches the providedpattern. Thepatternmay include the wildcard character.which matches exactly one lowercase English letter. All other characters in the pattern must match themselves exactly.
Inputs/Outputs
Candidates should implement a class containing these two methods, or provide functions capable of processing a sequence of such operations.
Constraints
- The total number of
addWordandsearchoperations will be up to approximately 10^5. - The length of any
wordorpatternwill be up to approximately 10^3 characters. - The solution must be implemented in C++.