Tap here to switch tabs
Problem
Submissions

Problem: Find The First Player to win K Games in a Row

med
30 min
Try to solve the Find The First Player to win K Games in a Row problem.

Statement

There are nn players numbered from 00 to n−1n - 1 standing in a queue in order of their indices. You are given an integer array skills of size nn, where skills[i] represents the skill level of player i. All elements in skills are distinct. You are also given an integer k.

The competition proceeds in consecutive rounds as follows:

  • The first two players at the front of the queue play a match against each other.

  • The player with the strictly greater skill level wins the match.

  • The winner remains at the front of the queue, while the loser moves to the very back of the queue.

The competition ends as soon as any player achieves kk consecutive victories.

Return the initial index of the player who wins kk games in a row.

Constraints:

  • n ==== skills.length

  • 2≤n≤1052 \leq n \leq 10^5

  • 1≤k≤1091 \leq k \leq 10^9

  • 1≤1 \leq skills[i] ≤106\leq 10^6

  • All integers in skills are unique.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Find The First Player to win K Games in a Row

med
30 min
Try to solve the Find The First Player to win K Games in a Row problem.

Statement

There are nn players numbered from 00 to n−1n - 1 standing in a queue in order of their indices. You are given an integer array skills of size nn, where skills[i] represents the skill level of player i. All elements in skills are distinct. You are also given an integer k.

The competition proceeds in consecutive rounds as follows:

  • The first two players at the front of the queue play a match against each other.

  • The player with the strictly greater skill level wins the match.

  • The winner remains at the front of the queue, while the loser moves to the very back of the queue.

The competition ends as soon as any player achieves kk consecutive victories.

Return the initial index of the player who wins kk games in a row.

Constraints:

  • n ==== skills.length

  • 2≤n≤1052 \leq n \leq 10^5

  • 1≤k≤1091 \leq k \leq 10^9

  • 1≤1 \leq skills[i] ≤106\leq 10^6

  • All integers in skills are unique.