"Word Search" is a grid-based puzzle. You are given an m x n board of characters and a string word. You need to determine if the word exists in the grid. The word can be constructed from letters of sequentially adjacent cells (horizontal or vertical), and the same letter cell may not be used more than once in a single word.
This is one of the most popular DFS on 2D Matrix problems. It tests your ability to navigate a grid, handle boundaries, and implement backtracking to explore multiple paths. It is asked by almost everyone, from Amazon and Apple to startup unicorns.
The pattern is Depth-First Search (DFS) with Backtracking.
Grid:
A B C
D E F
Word: ABED.
r < 0 or c >= cols before accessing the grid.For grid DFS, always check three things at the start of your recursive function:
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Word Search II | Hard | Solve | |
| Path with Maximum Gold | Medium | Solve | |
| Battleships in a Board | Medium | Solve | |
| The Knightâs Tour | Medium | Solve | |
| Pacific Atlantic Water Flow | Medium | Solve |