Search⌘ K
AI Features

Solution: Word Search

Explore how to apply backtracking and depth-first search to solve the word search problem on a 2D grid. Understand how to traverse the grid, handle cell visits, and efficiently check all possible paths to find a target word by moving horizontally or vertically through adjacent letters while avoiding revisits.

Statement

Given an m x n grid of characters, board, and a string word, return TRUE if word exists in the grid.

The word can be formed by connecting letters of sequentially adjacent cells. The cells are considered sequentially adjacent when neighbors are either horizontally or vertically neighbors. Each cell can be used only once while forming the word.

Constraints:

  • m ==== board.length

  • n == board[i].length, where 00 \leq i << m

  • ...