Loading...
Design a data structure that supports adding integers and finding the median efficiently.
Input: operations as add,num or find_median separated by semicolons. Output median results with 1 decimal place.
add,1;add,2;find_median;add,3;find_median
1.5 2.0
find_median is called, the median of the current data stream [1, 2] is calculated as the average of the two middle numbers, which is 21+2=1.5.find_median is called again, the median of the current data stream [1, 2, 3] is the middle number, which is 2.0.