Given an array of integers nums and a k with 1 <= k <= nums.length, return the k-th largest value. Duplicates count separately, so k = 1 is the maximum.
Kth Largest Value (Set 3) — the data. This set runs 4 cases: nums holds arrays of 12–30 items, with values from -30 to 57; k ranges over 1–3. The hidden cases are the largest of the set.
Example 1
kthLargestValue()
Input
nums =[-27,55,20,53,0,-21,11,20,14,-19,-21,16,46,-28,-9,-21,6,45,-15,55,-11], k =3
Output
53
Why
`kthLargestValue` returns `53`forthisinput.
Example 2
kthLargestValue()
Input
nums =[-24,-4,57,21,16,11,10,8,38,35,1,38], k =1
Output
57
Why
`kthLargestValue` returns `57`forthisinput.
Constraints
1<= k <=nums.length<=10^4-10^4<= nums[i]<=10^4
Every caseinthisset must pass: the first two are visible on Run, the last two unlock on Submit.
Topics
ArraysSortingHeap
Implement kthLargestValue in the editor and return the answer — printing it is never graded.