Design a data structure that supports addNum(num) to insert a number and findMedian() to return the median of all numbers seen so far. Both operations must be efficient enough to be called interleaved across a large stream.
findMedian() returns 1findMedian() returns 1.5findMedian() returns 2Constraints: `-10^5 ≤ num ≤ 10^5` · at most `5 * 10^4` calls to `addNum` and `findMedian`. Median of even count = average of two middle values; odd count = the single middle value.
Numbers arrive one at a time. After each, you owe the caller the median so far — before the next number shows up. The obvious shot: keep them sorted and read the middle.
Tap each incoming value to drop it into its sorted slot. The counter tallies every element the array has to shift right. Even on 3 elements the waste is visible — imagine 1000.