Skip to main content

Find Median from Data Stream

HardPremium

Design a data structure that supports the following operations:

add_num(int num): Adds a number to the current data stream.

find_median(): Returns the median of all numbers added so far.

Median is the middle value in a sorted list. If the list is even-sized, the median is the average of the two middle elements.

Example

Input: ["MedianFinder", "add_num", "add_num", "add_num", "find_median", "add_num", "find_median"] [[], [5], [15], [1], [], [3], []] Output: [None, None, None, None, 5.0, None, 4.0]