Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Rolling Latency Percentiles and Alerts

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

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

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