Design Add and Search Words Data Structure
Recognize the pattern
Brute force idea
A straightforward first read of Design Add and Search Words Data Structure is this: Store words in a list, for each search check every word with regex — per search. That instinct is useful because it follows the prompt literally, but it usually keeps revisiting work the problem is begging you to organize.
Better approach
A calmer way to see Design Add and Search Words Data Structure is this: Trie for addWord. For search: if the character is a letter, follow that branch. If it's '.', try ALL children branches (DFS). A word exists if any branch reaches an end-marked node. worst case, but typically much faster. The goal is not to be clever for its own sake, but to remember the one relationship that keeps the solution grounded as you move forward.
Key invariant
The truth you want to protect throughout Design Add and Search Words Data Structure is this: The '.' wildcard means you must explore all possible branches at that position. This turns a simple trie walk into a DFS — but the trie still prunes impossible paths at non-wildcard positions. If that remains true after every update, the rest of the reasoning has a stable place to stand.
Watch out for
A common way to get lost in Design Add and Search Words Data Structure is this: Trying to search iteratively — the wildcard requires branching, which needs recursion or a stack. Iterative search only works for exact character matches. Most mistakes here are not about syntax; they come from losing track of what your state, pointer, or structure is supposed to mean.