Skip to main content
Back to problems
#3175
Medium Algorithms

Find the first player to win k games in a row

Array Simulation
40.1% acceptance
Feb 24, 2026
139
16
A competition consists of n players numbered from 0 to n - 1. 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. The competition process: first two players play, higher skill wins. Winner stays at front, loser goes to end. First to win k games in a row wins. Return the initial index of the winning player.

Solution

Rust
Time O(n)
Space O(1)
LeetCode
solution.rs
impl Solution {
  pub fn find_winning_player(skills: Vec<i32>, k: i32) -> i32 {
    let k = k as usize;
    let n = skills.len();
    let mut front = 0usize;
    let mut wins = 0usize;

    for i in 1..n {
      if wins >= k {
        break;
      }
      if skills[front] > skills[i] {
        wins += 1;
      } else {
        front = i;
        wins = 1;
      }
    }
    front as i32
  }
}