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 2) — the data. This set runs 4 cases: nums holds arrays of 10–15 items, with values from -18 to 59; k ranges over 2–3. The hidden cases are the largest of the set.
Example 1
kthLargestValue()
Input
nums =[27,-18,13,2,33,18,23,28,23,23], k =3
Output
27
Why
`kthLargestValue` returns `27`forthisinput.
Example 2
kthLargestValue()
Input
nums =[56,22,-7,45,5,-3,53,-10,59,39,26,38], k =3
Output
53
Why
`kthLargestValue` returns `53`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.