Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
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
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess 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
Build my plan
Filter Noisy Robotic Sensor Streams
00:00
5 left

Filter Noisy Robotic Sensor Streams

MediumPython

Problem

Skild AI robot sensors can produce isolated spikes caused by vibration or transmission noise. Implement a causal median filter that replaces a reading when it differs too much from the recent filtered signal.

Given a list of numeric readings, an odd window_size, and an absolute threshold, process readings from left to right:

  1. For the first reading, output the reading unchanged.
  2. For every later reading, compute the median of up to the previous window_size output values.
  3. If the absolute difference between the current reading and that median is greater than threshold, output the median. Otherwise, output the current reading.
  4. The output value becomes part of the history used to process future readings.

Return a list containing the filtered values in their original order.

Formal Specification

  • Input: readings, a list of integers or floating-point numbers; window_size, a positive odd integer; and threshold, a nonnegative number.
  • Output: A list of numbers with the same length as readings.
  • When the available history has an even length, define its median as the average of its two middle values.

Constraints

  • 1 <= len(readings) <= 10^5
  • 1 <= window_size <= min(len(readings), 101)
  • window_size is odd
  • 0 <= threshold <= 10^6
  • -10^6 <= readings[i] <= 10^6

Function Signature

def filter_sensor_stream(readings, window_size, threshold):
Interviewer

Your question is Filter Noisy Robotic Sensor Streams. Start with the requirements in the Question tab.

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.
CodePython 3
Sign up free to run your codeLog inLn 2
Run your code to see test output here.