Design Add and Search Words Data Structure
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
Build a dictionary of words that supports wildcard lookups. In a query, the character . matches **exactly one** arbitrary letter; every other character must match literally. A query only matches words of the same length.
Implement:
- WordDictionary() creates an empty dictionary.
- addWord(word) stores word (lowercase letters only).
- search(word) returns true if some stored word matches the pattern word, otherwise false.
Queries contain lowercase letters and at most 2 dots.
Examples
Constraints
- 1 <= word.length <= 25
- `addWord` receives lowercase letters only.
- `search` receives lowercase letters and at most 2 `.` characters.
- At most 10^4 calls in total.
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.