Number of Players (for MTS2)
A group of friends are playing a video game together. During the game, each player earns a number of points. At the end of a round, players who achieve at least a certain rank k get to "level up" their characters to gain increased abilities. Given the scores of the players at the end of a round, how many players will be able to level up?
Note: Players with equal scores will have equal ranks, but the player with the next lower score will be ranked based on the position within the list of all players' scores. For example, if there are four players, and three of them tie for first place, their ranks are 1, 1, 1, and 4.
Note: No player with a score of 0 can level up, regardless of rank.
Complete the function numPlayers in the editor.
numPlayers has the following parameters:
- 1.
k: the cutoff rank to level up a player's character - 2.
scores[n]: the players' scores
Returns
int: the number of players who can level up after this round
1Example 1
These players' ranks are [1, 2, 2, 4]. Because the players need to have a rank of at least k = 3 to level up, only the first three players qualify. Therefore, the answer is 3.
2Example 2
The players achieve the ranks [5, 4, 3, 2, 1] in order. Since the cutoff k, is rank >= 4, there are 4 players who can level up.
3Example 3
The players achieve the ranks [4, 4, 3, 2, 1] in order. Since the cutoff rank is 4, all 5 players can level up.
Constraints
Limits and guarantees your solution can rely on.
1 ≤ n ≤ 10^50 ≤ scores[i] ≤ 100k ≤ n