Problems / Heap / Priority Queue / Find Median from Data Stream
#70 Hard Time O(log n) Space O(n) Animated

Find Median from Data Stream

Design a data structure to find the median from a data stream.

LeetCode ↗
Tutor Mode Build the mental model before you memorize the code.
  1. 1 Predict
  2. 2 Trace
  3. 3 Explain
  4. 4 Implement
Pattern Priority queue for the next best choice

Keep only candidates that may become the next answer, ordered by the priority that matters.

Approach: Two Heaps (Min and Max)
Click play to start
Step 0 / 0
Press play to start the visualization.

Steps