Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Client-Side API Rate Limiter
00:00
5 left

Client-Side API Rate Limiter

MediumPython

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):
Interviewer

Your question is Client-Side API Rate Limiter. 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
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.