#2018
Check if Word Can Be Placed In Crossword
specialist · 920 · lc medium +32 · verified · 50.7% accepted · 329 likes · top 39%
Description
Given an m x n crossword board containing lowercase letters (pre-filled cells), ' ' (empty), and '#' (blocked), determine if word can be placed horizontally or vertically (in either direction) such that: it avoids '#' cells; each cell is either empty or matches the letter; and no empty or letter cells border the word from outside its endpoints. Return true if placement is possible, otherwise false.
Example 1:
Input: board = [["#", " ", "#"], [" ", " ", "#"], ["#", "c", " "]], word = "abc"
Output: true
Explanation: The word "abc" can be placed as shown above (top to bottom).
Example 2:
Input: board = [[" ", "#", "a"], [" ", "#", "c"], [" ", "#", "a"]], word = "ac"
Output: false
Explanation: It is impossible to place the word because there will always be a space/letter above or below it.
Example 3:
Input: board = [["#", " ", "#"], [" ", " ", "#"], ["#", " ", "c"]], word = "ca"
Output: true
Explanation: The word "ca" can be placed as shown above (right to left).
Code
1
2
3