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). Return the result as an array.
Examples
shouldPrintMessage(1, 'foo'), shouldPrintMessage(2, 'bar'), shouldPrintMessage(3, 'foo')[true, true, false]'foo' prints at t=1 (first occurrence). 'bar' prints at t=2 (different message). 'foo' at t=3 is blocked because only 2 seconds passed since t=1, which is less than the 10-second cooldown.
shouldPrintMessage(15, 'hello'), shouldPrintMessage(20, 'world'), shouldPrintMessage(25, 'hello'), shouldPrintMessage(26, 'hello')[true, true, false, true]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.
shouldPrintMessage(0, 'start'), shouldPrintMessage(5, 'start'), shouldPrintMessage(10, 'start'), shouldPrintMessage(11, 'start')[true, false, false, true]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.