Pattern Recognition Drill
Medium Backtracking
The Problem
Does a word exist in a 2D grid? Move up/down/left/right, no cell reuse.
What approach would you use?
Think about it before scrolling down.
For each cell matching word[0], DFS in 4 directions. Mark visited, unmark on backtrack. O(m*n*4^L).
Common Trap
Must unmark visited cells on backtrack (not just mark) — other paths might need them.