Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Client-Side API Rate Limiter

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

Your question is Client-Side API 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

Implement a client-side rate limiter for API requests. Given a list of request timestamps in non-decreasing order, an integer max_requests, and an integer window_size, return a boolean array where each value indicates whether the corresponding request should be allowed under a sliding-window policy. A request is allowed only if fewer than max_requests requests were allowed in the last window_size seconds, including the current timestamp.

Constraints

  • 1 <= timestamps.length <= 10^5
  • 0 <= timestamps[i] <= 10^9
  • timestamps is sorted in non-decreasing order
  • 1 <= max_requests <= 10^5
  • 1 <= window_size <= 10^9

Function Signature

def rate_limit_requests(timestamps, max_requests, window_size):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output