Blocklist Dictionary That Answers Lookups With Dot Wildcards
Last updated: November 29, 2026
Quick Overview
Design a dictionary for a moderation blocklist that supports add_word(word) and search(pattern), where pattern contains lowercase letters and '.' characters that each match exactly one letter. search returns True if any stored word matches the whole pattern.
Meta
November 29, 20260
0
0 solved
Design a dictionary for a moderation blocklist that supports add_word(word) and search(pattern), where pattern contains lowercase letters and '.' characters that each match exactly one letter. search returns True if any stored word matches the whole pattern.
Integrity tooling at Meta lets reviewers probe a blocklist with partial spellings, which maps cleanly onto a trie with wildcard search. The interviewer is looking for a clean trie, a recursive or stack-based branch on '.', and a sensible discussion of worst-case cost.
What the Interviewer Expects
- Use a trie with an end-of-word flag
- Branch over all children only on '.', walk directly on letters
- Require the match to end on a word boundary, not just a prefix
- Discuss the worst case when patterns are all dots
- Consider bucketing by length to prune impossible matches
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 return all matching words instead of a boolean?
- Would you cache pattern results if the same probe repeats?
- How does the cost change if words are grouped by length first?
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_wordinserts lowercase words; duplicates are harmless.searchmust match the entire pattern, soba.does not matchbadplus a suffix likebadge.- Each
.matches exactly one le...
High-Level Design
Store words in a trie. search runs a DFS over (node, index). On a letter we follow the single child; on . we try every child. We succeed when the index reaches the end of the pattern on a node f...