Design a data structure that supports adding words and searching for a word, where the search may include the wildcard character '.' that can match any single letter.
addWord("bad"); addWord("dad"); addWord("mad"); search("pad")falsesearch(".ad"); search("b..")true, trueSolve it in the editor. Sign in free to run your Python or JavaScript against test cases, get a verdict, and track your attempts.
Solve on FeatCode →A trie (prefix tree) stores strings character by character along tree edges, so words sharing a prefix share the same path. It turns "does any word start with this prefix?" into a walk proportional to the prefix length instead of a scan of every word.
Original problem on LeetCode ↗