← All problems
Find Median from Data Stream
Design a data structure supporting addNum (insert a number from a stream) and findMedian (return the median of all numbers seen so far). Both operations should be efficient for a long stream.
Complexity
Time O(log n) add, O(1) median; Space O(n)
Common pitfalls
- Broken size invariant after inserts
- Python heapq is min-heap: negate for max-heap
Your solution
Log in to save your code and track progress.