Skip to content

Commit 38cfc6d

Browse files
committed
2056. Number of Valid Move Combinations On Chessboard: RETRY
1 parent 4b0025b commit 38cfc6d

File tree

2 files changed

+102
-0
lines changed

2 files changed

+102
-0
lines changed

src/solution/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,3 +1550,4 @@ mod s2050_parallel_courses_iii;
15501550
mod s2053_kth_distinct_string_in_an_array;
15511551
mod s2054_two_best_non_overlapping_events;
15521552
mod s2055_plates_between_candles;
1553+
mod s2056_number_of_valid_move_combinations_on_chessboard;
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
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 <= ri, ci <= 8
47+
* Each positions[i] is distinct.
48+
*
49+
*/
50+
pub 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+
57+
impl 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)]
66+
mod tests {
67+
use super::*;
68+
69+
#[test]
70+
#[ignore]
71+
fn test_2056_example_1() {
72+
let pieces = vec_string!["rook"];
73+
let positions = vec![vec![1, 1]];
74+
75+
let result = 15;
76+
77+
assert_eq!(Solution::count_combinations(pieces, positions), result);
78+
}
79+
80+
#[test]
81+
#[ignore]
82+
fn test_2056_example_2() {
83+
let pieces = vec_string!["queen"];
84+
let positions = vec![vec![1, 1]];
85+
86+
let result = 22;
87+
88+
assert_eq!(Solution::count_combinations(pieces, positions), result);
89+
}
90+
91+
#[test]
92+
#[ignore]
93+
fn test_2056_example_3() {
94+
let pieces = vec_string!["bishop"];
95+
let positions = vec![vec![4, 3]];
96+
97+
let result = 12;
98+
99+
assert_eq!(Solution::count_combinations(pieces, positions), result);
100+
}
101+
}

0 commit comments

Comments
 (0)