Given an integer array nums and an integer k, return the kth largest element in the array. Note that it is the kth largest element in the sorted order, not the kth distinct element. Can you solve it without sorting?
Example 1
Input: nums = [3,2,1,5,6,4], k = 2
Output: 5
Explanation: Sorted from largest to smallest, the array is 6, 5, 4, 3, 2, 1. The 2nd largest is 5.
Example 2
Input: nums = [3,2,3,1,2,4,5,5,6], k = 4
Output: 4
Explanation: Sorted from largest to smallest: 6, 5, 5, 4, 3, 3, 2, 2, 1. Duplicates count separately, so the 4th largest is 4.
Example 3
Input: nums = [1], k = 1
Output: 1
Explanation: The only element is the 1st largest.
Keep a min-heap holding the k largest elements seen so far. Push each number; whenever the heap grows past k, pop the smallest. The heap's root then holds the kth largest.
Run checks all cases above. Submit evaluates all test cases.