FastPrepFastPrep
Problem Brief

Number of Players (for MTS2)

FULLTIMEOA

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.

Function Description

Complete the function numPlayers in the editor.

numPlayers has the following parameters:

  1. 1. k: the cutoff rank to level up a player's character
  2. 2. scores[n]: the players' scores

Returns

int: the number of players who can level up after this round

1Example 1

Input
k = 3, scores = [100, 50, 50, 25]
Output
3
Explanation

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

Input
k = 4, scores = [20, 40, 60, 80, 100]
Output
4
Explanation

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

Input
k = 4, scores = [2, 2, 3, 4, 5]
Output
5
Explanation

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^5
  • 0 ≤ scores[i] ≤ 100
  • k ≤ n
public int numPlayers(int k, int[] scores) {
  // write your code here
}
Input

k

3

scores

[100, 50, 50, 25]

Output

3

Sign in to submit your solution.