Description

Design a logger system that receives messages with timestamps and returns true if the message should be printed (not printed in the last 10 seconds).

Examples

Input:shouldPrintMessage(1, 'foo'), shouldPrintMessage(2, 'bar'), shouldPrintMessage(3, 'foo')
Output:[true, true, false]
Explanation:

foo can't print within 10s.

Input:shouldPrintMessage(15, 'hello'), shouldPrintMessage(20, 'world'), shouldPrintMessage(25, 'hello'), shouldPrintMessage(26, 'hello')
Output:[true, true, false, true]
Explanation:

First 'hello' prints at timestamp 15. 'world' prints at 20 (different message). Second 'hello' at 25 is blocked (only 10 seconds passed since 15). Third 'hello' at 26 prints because 26-15=11 seconds have passed, exceeding the 10-second limit.

Input:shouldPrintMessage(0, 'start'), shouldPrintMessage(5, 'start'), shouldPrintMessage(10, 'start'), shouldPrintMessage(11, 'start')
Output:[true, false, false, true]
Explanation:

Same message 'start' is tested at different intervals. First prints at 0. At timestamp 5 (5 seconds later) it's blocked. At timestamp 10 (exactly 10 seconds) it's still blocked since more than 10 seconds must pass. At timestamp 11 (11 seconds later) it prints again.

Constraints

  • 0 ≤ timestamp ≤ 10⁹
  • Timestamps are in non-decreasing order.

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!