Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Telemetry Rate Limiter

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

Your question is Telemetry Rate Limiter. 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

Ancestry client applications send telemetry events that must be throttled before entering the telemetry pipeline. Implement a per-client sliding-window rate limiter that accepts an event only when that client has sent fewer than limit accepted events during the preceding window seconds.

Formal Specification

Implement throttle_telemetry(events, limit, window), where events is a list of [client_id, timestamp] pairs. client_id is a string, and timestamp is a nonnegative integer. Events are provided in nondecreasing timestamp order. Return a list of booleans, where the value at index i indicates whether event i is accepted.

For an event at time t, its active window is (t - window, t]. Expire timestamps less than or equal to t - window before checking the limit. Rejected events do not consume capacity. Each client has an independent limit.

Constraints

  • 0 <= len(events) <= 10^5
  • 1 <= limit <= 10^5
  • 1 <= window <= 10^9
  • Each event is [client_id, timestamp], where client_id is a string and timestamp is a nonnegative integer
  • Timestamps are nondecreasing
  • Rejected events do not consume capacity

Function Signature

def throttle_telemetry(events, limit, window):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output