Search⌘ K
AI Features

Solution: Word Search

Explore the backtracking method to solve the Word Search problem on a 2D grid. This lesson teaches you to implement depth-first search to find sequentially adjacent characters forming a word, handle boundary checks, and backtrack correctly to explore all possible paths with efficient use of resources.

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

  • 11 \leq m, n ...