← Backtracking

Pattern Recognition Drill

#81 — Word search

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.

Key Signals

Backtracking

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.

← #80 #82 →