The algorithm: Maintain two heaps: - maxHeap: stores the smaller half (max at top) - minHeap: stores the larger half (min at top) addNum: Add to one heap, then balance so sizes differ by at most findMedian: - If same size, average of both tops - If different sizes, the top of the larger heap The heaps give insertion and median retrieval.
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
$ curl repovive.com/roadmaps/maang-interview-prep/heaps-priority-queues/find-median-from-data-stream-solution
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████████████████████████████████████████████████████████████████████████████████████████████████████████