Word Search

Find if a word exists in a grid.

Problem: Given a grid and word, check if word exists as a path of adjacent cells (no reuse).

Approach: DFS from each cell matching the first character. Mark cells visited by modifying temporarily, restore after. Explore all four directions. Return true if any path completes the word.

Time: O(mn4L)O(m \cdot n \cdot 4^L) where LL is word length.

Space: O(L)O(L) for recursion stack.

See the implementation unit for code.