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 1) — the data. This set runs 4 cases: nums holds arrays of 6–8 items, with values from -27 to 59; k ranges over 1–2. The hidden cases are the largest of the set.
Example 1
kthLargestValue()
Input
nums =[49,3,43,57,16,59,4], k =1
Output
59
Why
`kthLargestValue` returns `59`forthisinput.
Example 2
kthLargestValue()
Input
nums =[18,13,-14,-23,39,-17], k =1
Output
39
Why
`kthLargestValue` returns `39`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.