dsa · medium
Kth Largest Element
GreyOrangeHeapArray
Return the k-th **largest** element of nums.
Arguments
nums— the input array of integersk— 1-indexed rank of the largest value to return (k = 1is the maximum)
**Example:** [3,2,1,5,6,4], k=2 → 5.
Heap piece used inside Dijkstra (priority queue).
Constraints
1 <= k <= nums.length <= 4*10^4 Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.
Examples
Example 1
Input: [3,2,1,5,6,4] 2 Expected: 5
Example 2
Input: [3,2,3,1,2,4,5,5,6] 4 Expected: 4