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
Rolling Averages and Outliers
00:00
5 left

Rolling Averages and Outliers

HardPython

Problem

Amazon CloudWatch receives telemetry records ordered by timestamp. Given a time-series of (timestamp, value) pairs, calculate the rolling average and determine whether each value is a statistical outlier compared with earlier values in the active time window.

For each record, use earlier records whose timestamps satisfy timestamp > current_timestamp - window_seconds as the baseline. Compute the population mean and standard deviation of that baseline. A value is an outlier when there are at least min_history baseline records and its absolute deviation from the baseline mean is greater than z_threshold * standard_deviation. If the baseline standard deviation is zero, any different value is an outlier. The rolling average includes the current value and the active earlier values.

Return one list per input record: [timestamp, rolling_average_rounded_to_2_decimals, is_outlier]. The first value is never an outlier if insufficient history exists.

Formal Specification

Implement process_telemetry(records, window_seconds, z_threshold, min_history), where records is a nondecreasing list of [integer_timestamp, numeric_value] pairs. Return a list of [integer, float, boolean] lists in the same order.

Constraints

  • 0 <= len(records) <= 10^6
  • Timestamps are nondecreasing integers
  • Values are finite numbers
  • 1 <= window_seconds <= 10^9
  • 0 < z_threshold <= 10^3
  • 1 <= min_history <= 10^6

Function Signature

def process_telemetry(records, window_seconds, z_threshold, min_history):
Interviewer

Your question is Rolling Averages and Outliers. 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.