Two Heaps Pattern: Find the Median of a Data Stream Without Sorting
6d ago · 16 min read · TLDR: Two Heaps partitions a stream into two sorted halves. A max-heap holds everything below the median; a min-heap holds everything above it. Keep the heaps size-balanced and you can read the median from either top in O(1) — no sorting needed, ever...
Join discussion
















