Logger Rate Limiter
Problem
Design a logger that suppresses duplicate messages. A message may be printed only if the same message text has not been printed in the previous 10 seconds. Implement Logger with:
shouldPrintMessage(timestamp, message): returnTrueif the message should be printed at this time (and record it), otherwiseFalse.
Calls arrive with non-decreasing timestamps. A message printed at time t blocks the same text until time t + 10 inclusive of t + 9; at t + 10 it may print again.
- Timestamps can grow into the billions of seconds.
- Each message is a short string, at most a few dozen characters.
- Expect up to about ten thousand calls.
Examples
(2, "warn")→True;(3, "error")→True;(4, "warn")→False;(9, "error")→False;(11, "warn")→False;(12, "warn")→Truebecause2 + 10 = 12.(0, "a"),(0, "a")→True, thenFalse; two calls at the same timestamp are still duplicates.(6, "x")→True;(16, "x")→True;(25, "x")→False; the timer restarts from the last printed occurrence, not the last attempt.
Hints
- For each distinct message, what single number do you need to remember to answer the next query?
- Store the earliest time the message may print again. Only update it when you actually print.
- Hash map from message to
next_allowed_time; print ifftimestamp >= next_allowed_time, and on print set it totimestamp + 10.
Last reviewed 8 September 2026
Approach · Solution (Python) · Complexity · Follow-ups · Company variations · Tests
The rest of this question — the worked approach, the Python solution with passing tests, complexity, follow-ups and how each company frames it — is part of the guides.
Get the full guide
Pick the company you're interviewing with. Each guide has every question tiered for that loop — one-time purchase, lifetime access.
Also in: Apple, Google, Meta, Microsoft, Netflix
Interviewing at more than one? All 6 guides for $499 · save $395
Not ready to buy? Get the free starter pack — 13 questions with full solutions.