Return the k-th largest value in nums, where k = 1 is the largest. Equal values count separately: in [5, 5, 3] the 2nd largest is 5 and the 3rd largest is 3.
Sorting the whole list works, but you only need one value. See if you can do it faster.
Example 1
Input:
kth_largest([3, 2, 1, 5, 6, 4], 2)
Output:
5
Sorted from largest: 6, 5, 4, 3, 2, 1. The 2nd is 5.
Example 2
Input:
kth_largest([5, 5, 3], 3)
Output:
3
Sorted from largest: 5, 5, 3. The 3rd is 3.
1 <= k <= len(nums) <= 2 * 10**5-10**9 <= nums[i] <= 10**9No results yet
Run your code to check it against the examples, or submit to run every test.