Find Median from Data Stream
The median is the middle value in an ordered integer list. Implement the MedianFinder class.

30:00

Find Median from Data Stream
hard
Topics
Companies

The median is the middle value in an ordered integer list. Implement the MedianFinder class.

Example 1:
Input: {"commands":["MedianFinder","addNum","addNum","findMedian","addNum","findMedian"],"values":[[],[1],[2],[],[3],[]]}
Output: [null,null,null,1.5,null,2.0]
Constraints:
  • 105num105-10^5 \leq \text{num} \leq 10^5

  • There will be at least one element in the data structure before calling findMedian.

  • At most 5×1045 \times 10^4 calls in total to addNum and findMedian.

Input
arr ={"commands":["MedianFinder","addNum","addNum","findMedian","addNum","findMedian"],"values":[[],[1],[2],[],[3],[]]}

addNum(1)

Max Heap (Left)

Empty

Min Heap (Right)

Empty

Adding: 1

Variables
No variables to display
DepthFunction Call
Stack empty
0/9