Skip to content

Commit a1a74d4

Browse files
committed
1900. The Earliest and Latest Rounds Where Players Compete: RETRY
1 parent 53e4510 commit a1a74d4

File tree

2 files changed

+97
-0
lines changed

2 files changed

+97
-0
lines changed

src/solution/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1432,3 +1432,4 @@ mod s1896_minimum_cost_to_change_the_final_value_of_expression;
14321432
mod s1897_redistribute_characters_to_make_all_strings_equal;
14331433
mod s1898_maximum_number_of_removable_characters;
14341434
mod s1899_merge_triplets_to_form_target_triplet;
1435+
mod s1900_the_earliest_and_latest_rounds_where_players_compete;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/**
2+
* [1900] The Earliest and Latest Rounds Where Players Compete
3+
*
4+
* There is a tournament where n players are participating. The players are standing in a single row and are numbered from 1 to n based on their initial standing position (player 1 is the first player in the row, player 2 is the second player in the row, etc.).
5+
* The tournament consists of multiple rounds (starting from round number 1). In each round, the i^th player from the front of the row competes against the i^th player from the end of the row, and the winner advances to the next round. When the number of players is odd for the current round, the player in the middle automatically advances to the next round.
6+
*
7+
* For example, if the row consists of players 1, 2, 4, 6, 7
8+
*
9+
* Player 1 competes against player 7.
10+
* Player 2 competes against player 6.
11+
* Player 4 automatically advances to the next round.
12+
*
13+
*
14+
*
15+
* After each round is over, the winners are lined back up in the row based on the original ordering assigned to them initially (ascending order).
16+
* The players numbered firstPlayer and secondPlayer are the best in the tournament. They can win against any other player before they compete against each other. If any two other players compete against each other, either of them might win, and thus you may choose the outcome of this round.
17+
* Given the integers n, firstPlayer, and secondPlayer, return an integer array containing two values, the earliest possible round number and the latest possible round number in which these two players will compete against each other, respectively.
18+
*
19+
* Example 1:
20+
*
21+
* Input: n = 11, firstPlayer = 2, secondPlayer = 4
22+
* Output: [3,4]
23+
* Explanation:
24+
* One possible scenario which leads to the earliest round number:
25+
* First round: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
26+
* Second round: 2, 3, 4, 5, 6, 11
27+
* Third round: 2, 3, 4
28+
* One possible scenario which leads to the latest round number:
29+
* First round: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
30+
* Second round: 1, 2, 3, 4, 5, 6
31+
* Third round: 1, 2, 4
32+
* Fourth round: 2, 4
33+
*
34+
* Example 2:
35+
*
36+
* Input: n = 5, firstPlayer = 1, secondPlayer = 5
37+
* Output: [1,1]
38+
* Explanation: The players numbered 1 and 5 compete in the first round.
39+
* There is no way to make them compete in any other round.
40+
*
41+
*
42+
* Constraints:
43+
*
44+
* 2 <= n <= 28
45+
* 1 <= firstPlayer < secondPlayer <= n
46+
*
47+
*/
48+
pub struct Solution {}
49+
50+
// problem: https://leetcode.com/problems/the-earliest-and-latest-rounds-where-players-compete/
51+
// discuss: https://leetcode.com/problems/the-earliest-and-latest-rounds-where-players-compete/discuss/?currentPage=1&orderBy=most_votes&query=
52+
53+
// submission codes start here
54+
55+
impl Solution {
56+
pub fn earliest_and_latest(n: i32, first_player: i32, second_player: i32) -> Vec<i32> {
57+
vec![]
58+
}
59+
}
60+
61+
// submission codes end
62+
63+
#[cfg(test)]
64+
mod tests {
65+
use super::*;
66+
67+
#[test]
68+
#[ignore]
69+
fn test_1900_example_1() {
70+
let n = 11;
71+
let first_player = 2;
72+
let second_player = 4;
73+
74+
let result = vec![3, 4];
75+
76+
assert_eq!(
77+
Solution::earliest_and_latest(n, first_player, second_player),
78+
result
79+
);
80+
}
81+
82+
#[test]
83+
#[ignore]
84+
fn test_1900_example_2() {
85+
let n = 5;
86+
let first_player = 1;
87+
let second_player = 5;
88+
89+
let result = vec![1, 1];
90+
91+
assert_eq!(
92+
Solution::earliest_and_latest(n, first_player, second_player),
93+
result
94+
);
95+
}
96+
}

0 commit comments

Comments
 (0)