Find the kth largest element in an unsorted array.
O(n)
O(1)
def findKthLargest(nums, k): # Min-Heap of size k heap = nums[:k] heapq.heapify(heap) for n in nums[k:]: if n > heap[0]: heapq.heappop(heap) heapq.heappush(heap, n) return heap[0]