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
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
Get started
Real-Time Anomaly Detection Algorithm
00:00
5 left

Real-Time Anomaly Detection Algorithm

MediumPython

Problem

Airbus Skywise receives telemetry values continuously from aircraft systems. Implement a bounded-memory detector that flags values which are unusually far from the recent signal level while adapting to gradual changes in the baseline.

Use an exponentially weighted mean and variance. For each incoming value, evaluate whether it is anomalous against the statistics accumulated from earlier values, then update the statistics with the new value. A value is anomalous when its absolute deviation from the current mean is greater than threshold standard deviations. Do not let the current value influence the decision made for that value.

Formal Specification

Implement detect_anomalies(values, alpha, threshold, warmup), where values is a list of numeric telemetry readings, alpha is the update factor in (0, 1], threshold is a positive float, and warmup is the number of prior readings required before detection begins. Return a Boolean list of the same length as values.

The detector must use memory independent of len(values), apart from the returned result. Treat readings during warmup as non-anomalous. If the prior variance is zero, flag a different value after warmup as anomalous.

Constraints

  • 1 <= len(values) <= 10^7
  • 0 < alpha <= 1
  • threshold > 0
  • 0 <= warmup < len(values)
  • Values are finite real numbers
  • The detector must maintain only constant-size state

Function Signature

def detect_anomalies(values, alpha, threshold, warmup):
Interviewer

Your question is Real-Time Anomaly Detection Algorithm. 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.
Code
Sign up free to run your codeLog inLn 2
Run your code to see test output here.