Skip to main content
hardBlind 75

Find Median from Data Stream

Build a data structure to find the median of a stream of numbers Median = middle value when sorted (or average of two middle values) Example: add_num(1), add_num(2), find_median() -> 1.5 add_num(3), find_median() -> 2.0

Two heaps: a max-heap for the lower half and a min-heap for the upper half, kept balanced (differ by at most 1). Median comes from comparing heap tops - O(log n) insertion, O(1) median lookup. The quintessential 'two heaps' pattern problem.

Arrays & HashingHeap / Priority QueueTwo PointersDesign

Meet Coco

Coco is an AI study partner, not a person. She listens while you explain your code, asks what a line does and never hands you the fix. Typing with Coco is free when you sign in, up to a daily limit. Talking with her out loud comes with the $79 pack. Anyone can open the editor and run their code.

1Median Finder - Basic Implementationmedium
2Part 2

Each locked part opens in the editor once the part before it passes.

Based onLeetCode