In a quiz contest, nums holds the points of each team. Wrong answers lose points, so a score can be negative. Find the k-th highest score.
Look at the array in sorted order from the biggest value. The k-th largest is the value at position k in that order. Equal scores are counted one by one, not as one value.
Try to solve it without sorting the whole array.
Examples
Example 1:
Input: nums = [9,4,7,1,8], k = 2
Output: 8
Explanation: From the biggest: 9, 8, 7, 4, 1. The 2nd one is 8.
Example 2:
Input: nums = [5,5,3,3,1], k = 3
Output: 3
Explanation: From the biggest: 5, 5, 3, 3, 1. The same score counts every time, so the 3rd one is 3.
Example 3:
Input: nums = [10], k = 1
Output: 10
Explanation: There is only one score.