Logger Rate Limiter
Problem
Design a logger that receives a stream of (timestamp, message) events and decides whether each message may be printed. A given message may be printed at most once every 10 seconds. shouldPrint(timestamp, message) returns true if it is allowed now, false otherwise.
Input / Output
- Input: a sequence of
shouldPrint(timestamp, message)calls. - Output: a boolean per call — true if the message is printed, false if suppressed.
Constraints
- Timestamps arrive in non-decreasing order.
- "At most once every 10 seconds" means a message printed at t is allowed again only at t+10 or later.
Example
shouldPrint(1,"foo")-> true;shouldPrint(2,"foo")-> false;shouldPrint(11,"foo")-> true.
added …