2056. Number of Valid Move Combinations On Chessboard Hard

@problem@discussion
#Array#String#Backtracking#Simulation



1/**
2 * [2056] Number of Valid Move Combinations On Chessboard
3 *
4 * There is an 8 x 8 chessboard containing n pieces (rooks, queens, or bishops). You are given a string array pieces of length n, where pieces[i] describes the type (rook, queen, or bishop) of the i^th piece. In addition, you are given a 2D integer array positions also of length n, where positions[i] = [ri, ci] indicates that the i^th piece is currently at the 1-based coordinate (ri, ci) on the chessboard.
5 * When making a move for a piece, you choose a destination square that the piece will travel toward and stop on.
6 * 
7 * 	A rook can only travel horizontally or vertically from (r, c) to the direction of (r+1, c), (r-1, c), (r, c+1), or (r, c-1).
8 * 	A queen can only travel horizontally, vertically, or diagonally from (r, c) to the direction of (r+1, c), (r-1, c), (r, c+1), (r, c-1), (r+1, c+1), (r+1, c-1), (r-1, c+1), (r-1, c-1).
9 * 	A bishop can only travel diagonally from (r, c) to the direction of (r+1, c+1), (r+1, c-1), (r-1, c+1), (r-1, c-1).
10 * 
11 * You must make a move for every piece on the board simultaneously. A move combination consists of all the moves performed on all the given pieces. Every second, each piece will instantaneously travel one square towards their destination if they are not already at it. All pieces start traveling at the 0^th second. A move combination is invalid if, at a given time, two or more pieces occupy the same square.
12 * Return the number of valid move combinations​​​​​.
13 * Notes:
14 * 
15 * 	No two pieces will start in the same square.
16 * 	You may choose the square a piece is already on as its destination.
17 * 	If two pieces are directly adjacent to each other, it is valid for them to move past each other and swap positions in one second.
18 * 
19 *  
20 * Example 1:
21 * <img alt="" src="https://assets.leetcode.com/uploads/2021/09/23/a1.png" style="width: 215px; height: 215px;" />
22 * Input: pieces = ["rook"], positions = [[1,1]]
23 * Output: 15
24 * Explanation: The image above shows the possible squares the piece can move to.
25 * 
26 * Example 2:
27 * <img alt="" src="https://assets.leetcode.com/uploads/2021/09/23/a2.png" style="width: 215px; height: 215px;" />
28 * Input: pieces = ["queen"], positions = [[1,1]]
29 * Output: 22
30 * Explanation: The image above shows the possible squares the piece can move to.
31 * 
32 * Example 3:
33 * <img alt="" src="https://assets.leetcode.com/uploads/2021/09/23/a3.png" style="width: 214px; height: 215px;" />
34 * Input: pieces = ["bishop"], positions = [[4,3]]
35 * Output: 12
36 * Explanation: The image above shows the possible squares the piece can move to.
37 * 
38 *  
39 * Constraints:
40 * 
41 * 	n == pieces.length 
42 * 	n == positions.length
43 * 	1 <= n <= 4
44 * 	pieces only contains the strings "rook", "queen", and "bishop".
45 * 	There will be at most one queen on the chessboard.
46 * 	1 <= xi, yi <= 8
47 * 	Each positions[i] is distinct.
48 * 
49 */
50pub struct Solution {}
51
52// problem: https://leetcode.com/problems/number-of-valid-move-combinations-on-chessboard/
53// discuss: https://leetcode.com/problems/number-of-valid-move-combinations-on-chessboard/discuss/?currentPage=1&orderBy=most_votes&query=
54
55// submission codes start here
56
57impl Solution {
58    pub fn count_combinations(pieces: Vec<String>, positions: Vec<Vec<i32>>) -> i32 {
59        0
60    }
61}
62
63// submission codes end
64
65#[cfg(test)]
66mod tests {
67    use super::*;
68
69    #[test]
70    fn test_2056() {
71    }
72}
73


Back
© 2025 bowen.ge All Rights Reserved.