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
Streaming Out-of-Bounds Anomaly Detection
00:00
5 left

Streaming Out-of-Bounds Anomaly Detection

HardPython

Problem

GM vehicle telemetry systems receive fixed-width sensor readings continuously. Given a finite stream for evaluation, identify readings where at least one sensor value falls outside a rolling statistical bound computed from the preceding readings.

For each reading, calculate the mean and population standard deviation for every sensor using up to the previous window_size readings. A value is anomalous when it is strictly less than mean - z_threshold * standard_deviation or strictly greater than mean + z_threshold * standard_deviation. Do not classify readings until at least window_size previous readings are available. Evaluate a reading before adding it to the rolling window.

If a sensor's previous-window standard deviation is zero, classify a different current value as anomalous and the same value as normal.

Formal Specification

Implement detect_anomalies(samples, window_size, z_threshold). samples is a nonempty list of equal-length numeric lists. Return a list of zero-based indices for readings that are anomalous in at least one dimension. The input is processed in chronological order.

Constraints

  • 1 <= len(samples) <= 10^5
  • 1 <= len(samples[0]) <= 50
  • All samples have the same number of dimensions
  • 1 <= window_size < len(samples)
  • 0 < z_threshold <= 10
  • All sensor values are finite numbers

Function Signature

def detect_anomalies(samples, window_size, z_threshold):
Interviewer

Your question is Streaming Out-of-Bounds Anomaly Detection. 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.