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.
nums = [3,2,1,5,6,4], k = 25nums = [3,2,3,1,2,4,5,5,6], k = 44PriorityQueue) of size kA min-heap of size k always holds the k largest elements seen so far. Its root is the smallest of those k — which is exactly the kth largest. When a new element comes in and pushes the heap to size k+1, we evict the minimum (root). This ensures we always keep the top-k candidates. At the end, the root is the answer.