Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Real-Time Telemetry Window Store

MediumPython00:00
Practice interviewer
In session
5 left
00:00

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.

You need to log in / sign up to run or submit.

Problem

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.

Constraints

  • 1 <= len(operations) <= 10^5
  • 0 <= timestamp <= 10^9
  • -10^6 <= value <= 10^6
  • Timestamps in add operations are non-decreasing
  • 1 <= k <= 10^9
  • At least one add occurs before any query

Function Signature

def process_telemetry(operations):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output