In a Meta live monitoring pipeline, event counts arrive one integer at a time. Implement a data structure that supports inserting a new integer from the stream and returning the median of all values seen so far at any moment.
Implement a function that processes a list of operations and returns the result for each median query.
operations: a list of operations{"op": "add", "value": x} where x is an integer{"op": "median"}median query contributes the current median.Example 1
operations = [{"op": "add", "value": 5}, {"op": "median"}, {"op": "add", "value": 2}, {"op": "median"}, {"op": "add", "value": 10}, {"op": "median"}][5, 3.5, 5][5], median is 5; after [5, 2], median is (2 + 5) / 2 = 3.5; after [5, 2, 10], median is 5.Example 2
operations = [{"op": "add", "value": -1}, {"op": "add", "value": -2}, {"op": "median"}][-1.5][-2, -1], so the median is (-2 + -1) / 2 = -1.5.1 <= len(operations) <= 10^5-10^9 <= value <= 10^9median query