Problem 07
Rate Limiter
Implement a RateLimiter(limit, windowMs) with allow(key, nowMs). Each canonical client key gets its own sliding window.
Requirements
- 01constructor(limit, windowMs) and allow(key, nowMs) returning true (permitted) or false (rejected).
- 02Canonicalize each key by trimming surrounding whitespace and lowercasing it before applying a budget.
- 03Rate-limit each canonical key independently over the half-open trailing interval (nowMs - windowMs, nowMs].
- 04Allow a request when fewer than limit accepted timestamps remain in that interval; rejected attempts do not consume capacity.
- 05Require positive integer limit and windowMs values and nondecreasing finite nowMs inputs.
Constraints
- • Submit one compact engineering spec, not implementation code.
- • The generated artifact must use the declared TypeScript adapter.
- • Scoring rewards observable behavior and prompt efficiency, not runtime.
Difficulty
expert
Target
10 min
Acceptance
—
Artifact
library