Hard · Trie DFS with Wildcards
Understand → Visualise → Practice.
For each query, return whether the dictionary contains a same-length word where dot matches any one character.
Store the words in a trie. A query walks it: a letter follows one child, while '.' tries every child. A match must end at a node marking a word end.
Insert each word and mark its end.
At position i, a letter follows that child; '.' recurses into every child.
At the end of the query, succeed only if the node marks a complete word.
O(L) per query without dots, up to O(26ᵈ × L) with d dots; O(total characters) space.
Accepting any node at the end of the query matches prefixes like "ba" against "bad".
Read the full guide first: Tries and Prefix Search.
Guest mode lets you understand, visualise and run the sample tests. Create a free account to submit and save your solutions.