Your question is Streaming Median for Live Events. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
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.def stream_median(operations):