Blocking Sliding-Window Rate Limiter

Asked at DRW · Coding Questions · Difficulty: Medium · Last asked Nov 23, 2026

A client sends requests to a service that accepts only a limited number of them in any stretch of time. Build the limiter that sits in front of the client. When a request would break the limit, it is not dropped: it waits and is sent at the earliest moment the limit allows. To keep it testable, time is an integer clock passed in by the caller, and the limiter returns the moment each request is actually sent instead of sleeping.

Loading the problem…