LC 703
LeetCode 703 · Easy

Kth Largest Element in a Stream

Return the kth largest element after each value is added.

Heap → · Medium frequency · Solve on LeetCode →

Try it

Step through the core mechanic. The simulator below runs the heap shape this problem is built on.

Walk the pattern

No dedicated step-through for this one yet. The shape is Heap — its pattern page has the interactive walkthrough, the reference implementation, and a five-problem progression that this problem sits inside.

The approach

Keep a min-heap of size k. The heap top is the kth largest. Each add pushes then pops if the size exceeds k, so updates are O(log k).

AspectValue
PatternHeap
Recognise it byRunning kth largest as values stream in.
Time complexityO(log k)
Space complexityO(k)
DifficultyEasy

Who asks it

Companies known to ask this problem, from public LeetCode company-tag aggregations. A signal of where to expect it, not a guarantee.