Practice/Amazon/Leetcode 2018. Check if Word Can Be Placed In Crossword
CodingOptional
You are given a rectangular grid representing a puzzle board and a target word. The grid contains three types of cells:
'#'): These are solid barriers where no letters can be placed' '): Empty spaces where any letter can be placedYour task is to determine whether the given word can be validly placed in the grid either horizontally or vertically, in either forward or backward direction.
A valid placement means:
Return true if at least one valid placement exists, otherwise return false.
m == board.length (number of rows)n == board[i].length (number of columns)1 <= m * n <= 2 * 10^51 <= word.length <= max(m, n)board[i][j] is either '#', ' ', or a lowercase English letterword consists only of lowercase English lettersExample 1:
Input: board = [["#", " ", "#"], [" ", " ", "#"], ["#", " ", "c"]], word = "abc" Output: true Explanation: The word can be placed vertically in column 1 (middle column) reading downward: position [0][1]='a', [1][1]='b', [2][1]='c'.
Example 2:
Input: board = [[" ", "#", "a"], [" ", "#", "c"], [" ", "#", "a"]], word = "aca" Output: true Explanation: The word matches the existing letters in column 2 reading from top to bottom.
Example 3:
Input: board = [["#", "#", "#"], ["#", "#", "#"], ["#", "#", "#"]], word = "test" Output: false Explanation: All cells are blocked, so there's no place to put any word.
Example 4:
Input: board = [[" ", " ", " ", " "]], word = "abcd" Output: true Explanation: The word fits perfectly in the single row horizontally.