LeetCode 703-variant Kth Largest with Dynamic K Summary
Generated by Claude with claude-opus-4-7
Quick facts
- Problem: Kth Largest Element in a Stream
- Topics:
Design,Heap (Priority Queue),Data Stream
Problem gist
Design a collection that supports two operations in any interleaving:
insert(num)— add a number to the collection.find_kth_largest(k)— return thek-th largest element currently in the collection.
The twist versus the original LeetCode 703 is that k is a parameter of every query and may change from call to call. The classic min-heap-of-size-k solution relied on k being fixed at construction so it could safely discard everything below the running k-th largest. Once k can grow on a later call, no element is safe to throw away, and the whole strategy has to change.