Max Heap (Tree View)
Heap Array
Extracted Elements (Largest to Smallest)

Phase

-
Current operation

Heap Size

0
Elements in heap

k

2
Target position

Result

-
kth largest
Click "Step" or "Play" to build the heap and find the kth largest element
Root (Max)
Current
Parent
Child
Extracted
Python Code - Kth Largest Element
def findKthLargest(nums, k):
    heap = []
    for n in nums:
        heappush(heap, n) # sift-up
    extracted = []
    while len(extracted) < k:
        extracted.append(heappop(heap))
    return extracted[k - 1]
 
# sift-up: bubble up if > parent
# sift-down: sink to larger child
# Max heap: parent >= children