Your question is Real-Time Telemetry Window Store. 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.
Design a data structure that stores a stream of vehicle sensor telemetry events and supports efficient real-time queries over a sliding time window. Each event is a pair (timestamp, value) for a single sensor, where timestamps are added in non-decreasing order. Implement a function that processes a list of operations and returns query results. Supported operations are: add(timestamp, value), avg(k) returning the average of values with timestamp >= current_timestamp - k + 1, and max(k) returning the maximum value in that same window. If the window is empty, return -1.
def process_telemetry(operations):