3175. Find The First Player to win K Games in a Row Medium

@problem@discussion
#Array#Simulation



1/**
2 * [3175] Find The First Player to win K Games in a Row
3 *
4 * A competition consists of n players numbered from 0 to n - 1.
5 * You are given an integer array skills of size n and a positive integer k, where skills[i] is the skill level of player i. All integers in skills are unique.
6 * All players are standing in a queue in order from player 0 to player n - 1.
7 * The competition process is as follows:
8 * 
9 * 	The first two players in the queue play a game, and the player with the higher skill level wins.
10 * 	After the game, the winner stays at the beginning of the queue, and the loser goes to the end of it.
11 * 
12 * The winner of the competition is the first player who wins k games in a row.
13 * Return the initial index of the winning player.
14 *  
15 * <strong class="example">Example 1:
16 * <div class="example-block">
17 * Input: <span class="example-io">skills = [4,2,6,3,9], k = 2</span>
18 * Output: 2
19 * Explanation:
20 * Initially, the queue of players is [0,1,2,3,4]. The following process happens:
21 * 
22 * 	Players 0 and 1 play a game, since the skill of player 0 is higher than that of player 1, player 0 wins. The resulting queue is [0,2,3,4,1].
23 * 	Players 0 and 2 play a game, since the skill of player 2 is higher than that of player 0, player 2 wins. The resulting queue is [2,3,4,1,0].
24 * 	Players 2 and 3 play a game, since the skill of player 2 is higher than that of player 3, player 2 wins. The resulting queue is [2,4,1,0,3].
25 * 
26 * Player 2 won k = 2 games in a row, so the winner is player 2.
27 * </div>
28 * <strong class="example">Example 2:
29 * <div class="example-block">
30 * Input: <span class="example-io">skills = [2,5,4], k = 3</span>
31 * Output: 1
32 * Explanation:
33 * Initially, the queue of players is [0,1,2]. The following process happens:
34 * 
35 * 	Players 0 and 1 play a game, since the skill of player 1 is higher than that of player 0, player 1 wins. The resulting queue is [1,2,0].
36 * 	Players 1 and 2 play a game, since the skill of player 1 is higher than that of player 2, player 1 wins. The resulting queue is [1,0,2].
37 * 	Players 1 and 0 play a game, since the skill of player 1 is higher than that of player 0, player 1 wins. The resulting queue is [1,2,0].
38 * 
39 * Player 1 won k = 3 games in a row, so the winner is player 1.
40 * </div>
41 *  
42 * Constraints:
43 * 
44 * 	n == skills.length
45 * 	2 <= n <= 10^5
46 * 	1 <= k <= 10^9
47 * 	1 <= skills[i] <= 10^6
48 * 	All integers in skills are unique.
49 * 
50 */
51pub struct Solution {}
52
53// problem: https://leetcode.com/problems/find-the-first-player-to-win-k-games-in-a-row/
54// discuss: https://leetcode.com/problems/find-the-first-player-to-win-k-games-in-a-row/discuss/?currentPage=1&orderBy=most_votes&query=
55
56// submission codes start here
57
58impl Solution {
59    pub fn find_winning_player(skills: Vec<i32>, k: i32) -> i32 {
60        0
61    }
62}
63
64// submission codes end
65
66#[cfg(test)]
67mod tests {
68    use super::*;
69
70    #[test]
71    fn test_3175() {
72    }
73}
74


Back
© 2025 bowen.ge All Rights Reserved.