Design a class to find the kth largest element in a stream.
Design a class to find the kth largest element in a stream.
Invariant: Min-Heap contains the K largest elements seen so far; minimum of these is the Kth largest.
To track K largest, maintain a Min-Heap; to track K smallest, maintain a Max-Heap.
Bottleneck: Heap rebalance takes log K.
Design a class to find the kth largest element in a stream.
Design a class to find the kth largest element in a stream.
Invariant: Min-Heap contains the K largest elements seen so far; minimum of these is the Kth largest.
To track K largest, maintain a Min-Heap; to track K smallest, maintain a Max-Heap.
Bottleneck: Heap rebalance takes log K.
Initialized pointers: Left at index 0 (4), Right at index 3 (2). Looking for target sum = 3.