Word Search
Return whether word can be traced in a letter board through orthogonally adjacent cells. A cell may not be reused in the same path.
Example 1
0,0A
0,1B
1,0D
1,1C
board = [["A","B"],["D","C"]]
word = "ABCD"trueExplanation
A->B->C->D moves right, down and left without revisiting a cell.
Example 2
0,0A
0,1B
1,0D
1,1C
board = [["A","B"],["D","C"]]
word = "ABA"falseExplanation
A->B->A would return from (0,1) to the already-used starting cell (0,0), which is forbidden.
Example 3
0,0X
board = [["X"]]
word = "X"trueExplanation
The only cell matches the one-letter word.
Constraints
- 1 <= rows, columns <= 6
- 1 <= len(word) <= 15
- Board and word contain English letters
Function contract
existArguments: json, jsonSolutionRuns on your device
Loading draft…
Run: 3 examples; Submit: 35 cases, on your device.
[["A","B"],["D","C"]]"ABCD"