~/problems
Problems
Basics first, then the classics, then company-style assessments. Every problem has tests you run right here; multi-level ones unlock as you go. See the roadmap.
Rolling windows and rate counters
QPS over the last N seconds, hit counters, rate limiters.
Main path: 8 problems, about 4 hours.
Notes
Recognise it when: you need "requests in the last N seconds", QPS per key, hit counters, or rate limiting.
- Exact, low volume: a deque of timestamps; pop from the left while
t - q[0] >= window. - High volume: time buckets: an array of N one-second buckets
(second, count)in a ring. On each hit, reset the bucket if its second is stale. The rolling sum is the sum of the fresh buckets (keep a running total to make it O(1)). - Per key:
dict[key] -> bucket ring. Evict idle keys. - Rate limiter: a token bucket (refill
rate * elapsed, cap at burst) or a sliding-window log or counter. - Thread safety: a lock per key or striped locks;
collections.Counterisn't atomic.
Gotchas: clock monotonicity (time.monotonic), window boundaries (≤ vs <), and memory growth from many keys.
8 problems
Practical systems
Streams & durability Rate counters, serialization, retrying work queues.
Rolling windows and rate counters guide
- Play first: The Gatekeeper 1-minute game Token bucket rate limiter
- Events in the last N seconds basics py · c++ · java easy
- Café drink counts over the last N seconds py · c++ · java easy
- Logger Rate Limiter py · c++ · java easy
- Token Bucket Rate Limiter code the boss py · c++ · java easy
- Page views in the last five minutes py · c++ · java easy
- Chat message events aggregation assessment 3 levels OpenAI py · c++ · java easy
- Key-value store with rolling QPS assessment 3 levels Databricks py · c++ · java medium
- Throttle requests per client assessment 4 levels py · c++ · java hard