Word Search

Hard

Given a board of letters and a word, return true if the word can be built from sequentially adjacent cells (horizontally or vertically).

The same cell may not be used twice.

Example 1

wordSearch()
Input
board = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]], word = "ABCCED"
Output
true

Example 2

wordSearch()
Input
board = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]], word = "SEE"
Output
true
Constraints
1 <= m, n <= 6
1 <= word.length <= 15
Cells hold a single uppercase letter.

Topics

MatrixBacktrackingDepth-First Search

Implement wordSearch in the editor and return the answer — printing it is never graded.