Ctrl K

K-th Highest Score

Medium
You have the scores of a competition's participants as an integer array scores, in no particular order. Find the score that lands at position rank when they are lined up from highest to lowest. Equal scores take separate places: in [9, 9, 4], second place is 9, not 4. Sorting the whole array works. Try to manage without it.
Example 1
scores=[40, 95, 12, 70, 88], rank=3 → 70

In descending order: 95, 88, 70, 40, 12. Third place is 70.

Example 2
scores=[50, 80, 80, 20], rank=2 → 80

Repeats count separately: 80, 80, 50, 20, so second place is 80 too.

Example 3
scores=[-5], rank=1 → -5
Constraints
  • 1 ≤ rank ≤ len(scores) ≤ 10⁵
  • -10⁴ ≤ scores[i] ≤ 10⁴
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsMost Common Values MediumNearest Points to the Base MediumK-th Largest Corner XOR MediumK-th Biggest Long Number MediumK-th Code by Its Last Digits Medium
loading Python…
Input
scores=[40, 95, 12, 70, 88], rank=3
Expected
70

Run checks the first 3 tests in your browser. Submit checks all 81 tests on the server, hidden ones included.