Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Start free
Efficient Sensor Stream Processing
00:00
5 left

Efficient Sensor Stream Processing

EasyPython

Problem

Zoox autonomy services may receive long sequences of nearly identical sensor readings. Implement an in-place compressor that removes redundant readings while preserving the original order and minimizing memory use.

A reading is represented as [timestamp, x, y]. Always retain the first reading. For every later reading, retain it if either of these conditions is true:

  1. Its timestamp differs from the last retained reading by more than max_interval.
  2. The absolute difference in x or y from the last retained reading is greater than epsilon.

Write retained readings into the beginning of the original readings list. Do not allocate a second list, and do not delete or resize the unused suffix. Return the number of retained readings. The valid compressed output is the prefix readings[:returned_count].

Formal Specification

Implement compress_sensor_stream(readings, epsilon, max_interval), where readings is a mutable list of three-element numeric lists. The function returns an integer count and mutates readings in place.

Constraints

  • 0 <= len(readings) <= 10^7
  • Each reading has exactly three numeric values: timestamp, x, and y
  • Timestamps are nondecreasing
  • 0 <= epsilon
  • 0 < max_interval
  • All values are finite

Function Signature

def compress_sensor_stream(readings, epsilon, max_interval):
Interviewer

Whenever you're ready, walk me through your approach or go straight to the code. The requirements are in the Question tab.

Sign up free to run or submit. Log in
Code
Sign up free to run your code. Your draft is saved.Run with a free accountLog inLn 2
Run your code to see test output here.