2018. Check if Word Can Be Placed In Crossword Medium

@problem@discussion
#Array#Matrix#Enumeration



1/**
2 * [2018] Check if Word Can Be Placed In Crossword
3 *
4 * You are given an m x n matrix board, representing the current state of a crossword puzzle. The crossword contains lowercase English letters (from solved words), ' ' to represent any empty cells, and '#' to represent any blocked cells.
5 * A word can be placed horizontally (left to right or right to left) or vertically (top to bottom or bottom to top) in the board if:
6 * 
7 * 	It does not occupy a cell containing the character '#'.
8 * 	The cell each letter is placed in must either be ' ' (empty) or match the letter already on the board.
9 * 	There must not be any empty cells ' ' or other lowercase letters directly left or right of the word if the word was placed horizontally.
10 * 	There must not be any empty cells ' ' or other lowercase letters directly above or below the word if the word was placed vertically.
11 * 
12 * Given a string word, return true if word can be placed in board, or false otherwise.
13 *  
14 * Example 1:
15 * <img alt="" src="https://assets.leetcode.com/uploads/2021/10/04/crossword-ex1-1.png" style="width: 478px; height: 180px;" />
16 * Input: board = [["#", " ", "#"], [" ", " ", "#"], ["#", "c", " "]], word = "abc"
17 * Output: true
18 * Explanation: The word "abc" can be placed as shown above (top to bottom).
19 * 
20 * Example 2:
21 * <img alt="" src="https://assets.leetcode.com/uploads/2021/10/04/crossword-ex2-1.png" style="width: 180px; height: 180px;" />
22 * Input: board = [[" ", "#", "a"], [" ", "#", "c"], [" ", "#", "a"]], word = "ac"
23 * Output: false
24 * Explanation: It is impossible to place the word because there will always be a space/letter above or below it.
25 * Example 3:
26 * <img alt="" src="https://assets.leetcode.com/uploads/2021/10/04/crossword-ex3-1.png" style="width: 478px; height: 180px;" />
27 * Input: board = [["#", " ", "#"], [" ", " ", "#"], ["#", " ", "c"]], word = "ca"
28 * Output: true
29 * Explanation: The word "ca" can be placed as shown above (right to left). 
30 * 
31 *  
32 * Constraints:
33 * 
34 * 	m == board.length
35 * 	n == board[i].length
36 * 	1 <= m * n <= 2 * 10^5
37 * 	board[i][j] will be ' ', '#', or a lowercase English letter.
38 * 	1 <= word.length <= max(m, n)
39 * 	word will contain only lowercase English letters.
40 * 
41 */
42pub struct Solution {}
43
44// problem: https://leetcode.com/problems/check-if-word-can-be-placed-in-crossword/
45// discuss: https://leetcode.com/problems/check-if-word-can-be-placed-in-crossword/discuss/?currentPage=1&orderBy=most_votes&query=
46
47// submission codes start here
48
49impl Solution {
50    pub fn place_word_in_crossword(board: Vec<Vec<char>>, word: String) -> bool {
51        false
52    }
53}
54
55// submission codes end
56
57#[cfg(test)]
58mod tests {
59    use super::*;
60
61    #[test]
62    fn test_2018() {
63    }
64}
65


Back
© 2025 bowen.ge All Rights Reserved.