Dictionary Lookup Where Dots Match Any Single Letter
Last updated: November 29, 2026
Quick Overview
Design a structure supporting addWord(word) and search(pattern), where pattern may contain '.' characters that each match exactly one arbitrary letter.
0
0
0 solved
Design a structure supporting addWord(word) and search(pattern), where pattern may contain '.' characters that each match exactly one arbitrary letter.
Shows up in Google technical screens as a crossword helper or a log-search feature with single-character wildcards. The interviewer is probing whether you branch only at wildcards and keep exact characters as single child lookups.
What the Interviewer Expects
- Use a trie with an end-of-word flag
- Branch over all children only on a dot
- Return as soon as any branch succeeds
- Analyze worst-case cost when the pattern is all dots
- Discuss iterative versus recursive search
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you support '*' meaning any run of letters?
- How would you bucket words by length to prune all-dot patterns?
- How would you return all matches instead of a boolean?
- What if words are added from many threads at once?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
add_word(word) inserts a lowercase word. search(pattern) returns True if any inserted word has the same length as pattern and matches it position by position, where . matches any letter. Searc...
High-Level Design
Store words in a trie with an end flag. Search is a DFS over pattern positions. For a normal letter there is at most one child to follow, so the path stays linear. For a dot we must try every child at...