Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Real-Time Anomaly Detection Algorithm

MediumPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Real-Time Anomaly Detection Algorithm. Start with the requirements on the right.

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.

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):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output