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
Rolling Latency Percentiles and Alerts
00:00
5 left

Rolling Latency Percentiles and Alerts

HardPython

Problem

Anthropic monitors Claude token-generation latency from an ordered stream of completed requests. Given latency values in arrival order, compute rolling p50 and p95 values and identify requests whose latency is more than 1.5 times the previous window's p95.

Return one result for every complete window. The first window cannot be classified as anomalous because it has no preceding window.

Formal Specification

Implement rolling_latency_anomalies(latencies, window_size), where latencies is a list of non-negative integers and window_size is a positive integer. Return a list of dictionaries in chronological order. Each dictionary must contain:

  • index: the ending index of the current window
  • p50: the current window's 50th percentile
  • p95: the current window's 95th percentile
  • anomalous: whether the current window's newest latency is greater than 1.5 * the preceding window's p95

Use the nearest-rank percentile: rank ceil(percentile * window length / 100), counting ranks from 1. For example, with four values, p50 is the second-smallest value and p95 is the largest value.

Constraints

  • 1 <= len(latencies) <= 10^5
  • 1 <= window_size <= len(latencies)
  • 0 <= latencies[i] <= 10^9
  • The input is ordered by arrival time

Function Signature

def rolling_latency_anomalies(latencies, window_size):
Interviewer

Your question is Rolling Latency Percentiles and Alerts. 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.