Word Search with Eight-Direction Adjacency
Problem statement
Given a square character grid board and a nonempty string word, return true if the word can be formed by a path through the grid.
From each cell, the path may move to any of its eight horizontal, vertical, or diagonal neighbors. A path may change direction between characters, but it cannot use the same cell more than once.
Function
wordExists8Directions(board: char[][], word: String) → booleanExamples
Example 1
board = [["A","B"],["C","D"]]word = "AD"return = trueThe path moves diagonally from the upper-left A to the lower-right D.
Example 2
board = [["A","B"],["C","D"]]word = "ABA"return = falseThe only A would need to be reused after visiting B, which is forbidden.
Constraints
1 <= board.length <= 6board[i].length = board.length1 <= word.length <= board.length * board.length- The grid and word contain uppercase and lowercase English letters, matched case-sensitively.