359. Logger Rate Limiter

Practice Logger Rate Limiter for free on NudgeCode: Easy, Array & Hash Table pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.

Design a logger that receives a stream of messages with timestamps (in seconds) and suppresses repeats: a message may be printed only if the same message has not been printed in the last 10 seconds. Concretely, if a message was printed at time t, the same message is blocked until time t + 10.

Messages arrive in non-decreasing timestamp order; several messages can share a timestamp.

Each test is a list of operations and their arguments; the expected output lists what each call returns (null for the constructor).

Example

["Logger","shouldPrintMessage","shouldPrintMessage","shouldPrintMessage","shouldPrintMessage","shouldPrintMessage","shouldPrintMessage"]
[[],[1,"foo"],[2,"bar"],[3,"foo"],[8,"bar"],[10,"foo"],[11,"foo"]]
->  [null,true,true,false,false,false,true]

Constraints