Word Search - Find word - aloalgo

Word Search - Find word

Medium

You are given an m x n board of characters and a word.

Your task is to determine if the word can be constructed from sequentially adjacent cells on the board. Adjacent cells are defined as those that are horizontally or vertically neighboring.

Note that:

  • Each cell on the board may not be used more than once to form the word.
  • board[i][j] and word consist of only lowercase English letters.

Return true if the word exists in the board, otherwise return false.

Example 1

Inputs
board = [["c", "a"], ["d", "t"]]
word = "cat"
Output
True
Explanation:

The word 'cat' can be formed from adjacent letters in the grid: c -> a -> t.

Example 2

Inputs
board = [["c", "a"], ["t", "d"]]
word = "cat"
Output
False
Explanation:

The word 'cat' cannot be formed from adjacent letters in the grid. Note that letters must be adjacent horizontally or vertically, not diagonally.

Example 3

Inputs
board = [["t", "o"], ["s", "p"]]
word = "stops"
Output
False
Explanation:

The word 'stops' cannot be formed from adjacent letters in the grid without reusing position twice.

Loading...
Inputs
board = [["c", "a"], ["d", "t"]]
word = "cat"
Output
True

Hello! I am your ✨ AI assistant. I can provide you hints, explanations, give feedback on your code, and more. Just ask me anything related to the problem you're working on!