Find The First Player to win K Games in a Row - Practice Coding | SlaveCode
0
0123456789
0
0123456789
:
0
0123456789
0
0123456789
3175. Find The First Player to win K Games in a Row
Medium
30 Points
Array
Simulation
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.
All players are standing in a queue in order from player 0 to player n - 1.
The competition process is as follows:
The winner of the competition is the first player who wins k games in a row.
Return the initial index of the winning player.
Examples
Example 1
Input: skills = [4,2,6,3,9], k = 2
Output: 2
Explanation:
Initially, the queue of players is [0,1,2,3,4] . The following process happens:
Player 2 won k = 2 games in a row, so the winner is player 2.
Example 2
Input: skills = [2,5,4], k = 3
Output: 1
Explanation:
Initially, the queue of players is [0,1,2] . The following process happens:
Player 1 won k = 3 games in a row, so the winner is player 1.
Constraints
n == skills.length
2 <= n <= 105
1 <= k <= 109
1 <= skills[i] <= 106
All integers in skills are unique.
3175. Find The First Player to win K Games in a Row
Medium
30 Points
Array
Simulation
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.
All players are standing in a queue in order from player 0 to player n - 1.
The competition process is as follows:
The winner of the competition is the first player who wins k games in a row.
Return the initial index of the winning player.
Examples
Example 1
Input: skills = [4,2,6,3,9], k = 2
Output: 2
Explanation:
Initially, the queue of players is [0,1,2,3,4] . The following process happens:
Player 2 won k = 2 games in a row, so the winner is player 2.
Example 2
Input: skills = [2,5,4], k = 3
Output: 1
Explanation:
Initially, the queue of players is [0,1,2] . The following process happens:
Player 1 won k = 3 games in a row, so the winner is player 1.