Pattern Recognition Drill
Hard Tries
The Problem
Given a board of characters and a list of words, find all words that can be formed by adjacent cells.
What approach would you use?
Think about it before scrolling down.
Build trie from words. DFS from each cell, walking the trie simultaneously. Prune when no trie child. O(m*n*4^L).
For each word, backtrack on board. Works but repeats work across words. O(W*m*n*4^L).
Common Trap
Without the trie, you'd re-explore the board for each word. The trie lets you search all words in one traversal.