Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Real-Time Telemetry Window Store

MediumPython00:00
I
Practice interviewer
Your interviewer
In session
I
Interviewer

Welcome to the Python screen.

The question is on your right: Real-Time Telemetry Window Store. Read through the requirements first.

Run and submit your code as often as you need. You also have five interviewer messages this session - want to talk through your approach, or are you ready to start coding?

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