Kth Largest Element
Return the k-th largest item of nums when the items are sorted from biggest to smallest. Duplicates count separately: in [5, 5, 3] the 2nd largest is 5.
Example 1
nums [3,2,1,5,6,4]
k 2
returns 5
Sorted high to low: 6, 5, 4, ... so the 2nd is 5.
Example 2
nums [3,2,3,1,2,4,5,5,6]
k 4
returns 4
6, 5, 5, 4: the 4th is 4.
Constraints
1 <= k <= len(nums) <= 40-100 <= nums[i] <= 100
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Sorting and searching problems
- Kth Smallest Distinct ValueBeginner
- Maximum Product of Two ElementsBeginner
- Median of the ListBeginner
- Names in OrderBeginner
- Shortest Words FirstBeginner
- Sort by Last DigitBeginner
- Strictly Increasing CheckBeginner
- Top Three ValuesBeginner