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
Parse Counters and Flag Anomalies
00:00
5 left

Parse Counters and Flag Anomalies

MediumPython

Problem

At Datadog, performance counters are emitted as log lines in the format name=value. Write a function that parses a list of counter strings and flags anomalous counters based on recent history.

A line is valid only if it contains exactly one = and the value is a valid integer. Ignore invalid lines. For each counter name, keep the sequence of parsed values in input order. A counter value is considered anomalous if it is at least threshold greater than the average of the previous window_size valid values for the same counter. If fewer than window_size previous values exist for that counter, do not evaluate anomaly status for that occurrence.

Return a list of anomalies in the order they are detected. Each anomaly should be represented as [name, index, value], where index is the original position in the input list.

Formal Specification

  • Input: lines as a list of strings, window_size as an integer, threshold as an integer
  • Output: A list of [counter_name, original_index, counter_value]

Constraints

  • 1 <= len(lines) <= 10^5
  • 1 <= window_size <= 10^4
  • 0 <= threshold <= 10^9
  • Each valid line has exactly one '=' and a non-empty counter name
  • Parsed integer values are in the range [-10^9, 10^9]

Function Signature

def flag_counter_anomalies(lines, window_size, threshold):
Interviewer

Your question is Parse Counters and Flag Anomalies. 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.