Word dictionary with wildcards
Design a word dictionary supporting add and wildcard search. Process operations: ["add", word] inserts a lowercase word; ["search", pattern] returns whether any added word matches the pattern, where '.' in the pattern matches any single character (all other characters match literally). The pattern length always equals a stored word's length to match. Return the list of boolean results for the search operations in order. Build a trie and DFS over branches when you hit a '.'.
Implement
wildcard_dictionary(ops: list) → list[bool]Examples
in
[[["add","bad"],["add","dad"],["add","mad"],["search","pad"],["search","bad"],["search",".ad"],["search","b.."]]]out[false,true,true,true]What a strong answer looks like
State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
0:00 of about 30 min
solution.py
InputExpectedGot
[[["add","bad"],["add","dad"],["add","mad"],["search","pad"],["search","bad"],["search",".ad"],["search","b.."]]][false,true,true,true]not run yetsample