Qualifying Candidates
EasyP3Coding
scores holds the contest score of each candidate. Candidates are ranked from the highest score: equal scores share a rank, and the next distinct score gets a rank equal to one plus the number of candidates with a strictly higher score. For example, scores [90, 90, 90, 90, 50] have ranks 1, 1, 1, 1, 5.
Return how many candidates have a rank less than or equal to k.
Example 1
- Input
- scores = [90,90,80,70], k = 3
- Output
- 3
- Why
- Ranks are 1,1,3,4. Three candidates have rank <= 3.
Example 2
- Input
- scores = [90,90,90,90,50], k = 2
- Output
- 4
- Why
- The four tied candidates share rank 1; 50 has rank 5.
Example 3
- Input
- scores = [10,20,30], k = 1
- Output
- 1
Constraints
- 1 <= scores.length <= 10^5
- 0 <= scores[i] <= 10^9
- 1 <= k <= 10^5
Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
Run checks the 3 visible tests, Submit all 11. ⌘Enter runs, ⌘⇧Enter submits.