Skip to main content
All Questions

Write a rate limiter: given a time window and a limit, return how many of each event's operations are processed so that no consumer exceeds the limit within any window.

Unlock detailed company stats for this questionUpgrade
Rate Limit API: events arrive as (unix timestamp, number of operations, consumer). Write a class constructed with time_window (seconds, inclusive at both ends) and limit, with a method rate_limit(event) returning how many of the event's operations will be processed, such that no consumer is allowed more than limit operations within any time_window. Events arrive in non-decreasing timestamp order.

Community answers

No answers contributed by the community yet.

Related courses

Course

Behavioral Interviews: A Practical Guide for Engineers

Get offers at the level you deserve. Prep for senior+ behavioral interviews at FAANG and Tier-1 companies. Made with staff and principal engineers from Meta, Netflix, Google, and more. Avoid downleveling, elevate past projects, and stop sounding like a robot.

Course

Software Engineering Interview Prep

Land your dream software engineering role at Google, Amazon, Microsoft, Meta, Apple, and other top companies. Learn from mock interviews, frameworks, and advice from senior candidates—practice data structures, algorithms, system design, people management, behavioral interviews, and more.