ReviseAlgo Logo
HardHigh Frequency30 min

Running Median (Two Heaps)

Maintain the median of a data stream using a max-heap and a min-heap.

Two heaps: max-heap for lower half, min-heap for upper half. Balance sizes so |lower| - |upper| Γëñ 1. Median = avg of two tops or single top.

Running Median — Two Heaps