Description
Solutions
Num Players
📚RELATED PROBLEMS
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 get to "level up" their characters to gain increase abilities.
Given the score 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 players
tie for the 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:
int k
: an integer denoting the cutoff rank for leveling up a player's characterint[] scores
: an array of integers denoting the scores of playersReturns
int
: the number of players who can level up after their roundExample 1:
Input: k = 3, scores = [100, 50, 50, 25]
Output: 3
Explanation:These players's ranks are [1, 2, 2, 4]. Because the players need to have rank of at least 3 to level up, only the first three players qualify. Therefore, the answer is 3.
Example 2:
Input: k = 4, scores = [20, 40, 60, 80, 100]
Output: 4
Explanation:In order, the players achieve the ranks [5, 4, 3, 2, 1]. Since the cutoff, k, is rank >= 4, there are 4 players who will be able to level up.
Constraints:
1 <= n <= 105
0 <= scores[i] <= 100
k <= n
Related Problems
Testcase
Result
Case 1
input:
output: