Intuition
This problem is a classic search scenario perfectly suited for a **Depth First Search (DFS)** with **backtracking**.
- Iterate and Initiate: We must try starting a search from every single cell, as the word can begin anywhere.
- Depth First Search (DFS): From a valid starting cell, we recursively explore neighbors (up, down, left, right) to find the next character of the word.
- Marking (Avoid Reuse): To prevent using the same cell twice in a path, we mark it as visited (e.g., with '#') before exploring from it.
- Backtracking: If a path fails, we must "un-mark" the cell, restoring its original character. This allows it to be used in different future paths.
Step-by-Step Code
Live Visualization
Algorithm States
Call Stack
Stack is empty