Word dictionary with wildcards
Your task
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 '.'.
Examples
wildcard_dictionary(ops: list) -> list[bool]Example 1
Input
wildcard_dictionary([["add", "bad"], ["add", "dad"], ["add", "mad"], ["search", "pad"], ["search", "bad"], ["search", ".ad"], ["search", "b.."]])Output
[False, True, True, True]