Straight-Line Word Search
Problem statement
Given a rectangular grid of characters and a nonempty word, return true when the word appears in one straight line.
You may start at any cell and choose one of the eight horizontal, vertical, or diagonal directions. After choosing the direction, every next character must be in the next cell along that same direction. The direction cannot change and the grid does not wrap.
Function
containsStraightWord(board: String[], word: String) → booleanExamples
Example 1
board = ["CAT","XXX","DOG"]word = "CAT"return = trueCAT appears left to right in the first row.
Example 2
board = ["AXX","XBX","XXC"]word = "ABC"return = trueABC appears on the main diagonal.
Example 3
board = ["AB","CD"]word = "ACB"return = falseThe letters require a direction change, which is forbidden.
Constraints
1 <= board.length, board[i].length <= 200.- All rows have equal length.
1 <= word.length <= 200.- The grid and word contain case-sensitive English letters.