Word Search
Given an m x n grid of characters board and a string word, return true if word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically neighboring. The same cell may not be used more than once within a single word path.
Open official problem prompt ↗Decide whether the word can be traced as a self-avoiding path through orthogonally adjacent grid cells.
Like a word-search puzzle: put your finger on a matching letter and see if you can walk to neighboring letters to spell the word without crossing your own trail.
- Input
- board = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]], word = "ABCCED"
- Output
- true
- Why
- The path A(0,0) -> B(0,1) -> C(0,2) -> C(1,2) -> E(2,2) -> D(2,1) walks adjacent cells spelling ABCCED without reusing a cell.
m == board.lengthn == board[i].length1 <= m, n <= 61 <= word.length <= 15board and word consist of only lowercase and uppercase English letters