Design a logger system that receives a stream of messages along with their timestamps. Each unique message should only be printed at most every 10 seconds (i.e. a message printed at timestamp t will prevent other identical messages from being printed until timestamp t + 10). All messages will come in chronological order. Several messages may arrive at the same timestamp. Implement the Logger class: - Logger() Initializes the logger object. - bool shouldPrintMessage(int timestamp, string message) Returns true if the message should be printed in the given timestamp, otherwise returns false.
Example 1
Input: operations = ["Logger","shouldPrintMessage","shouldPrintMessage","shouldPrintMessage","shouldPrintMessage","shouldPrintMessage","shouldPrintMessage"], arguments = [[],[1,"foo"],[2,"bar"],[3,"foo"],[8,"bar"],[10,"foo"],[11,"foo"]]
Output: [null,true,true,false,false,false,true]
Explanation: "foo" prints at t = 1, so it is blocked until t = 11. The calls at t = 3 and t = 10 are rejected, and t = 11 prints again. "bar" prints at t = 2, so the call at t = 8 is rejected because it is before t = 12.
Example 2
Input: operations = ["Logger","shouldPrintMessage"], arguments = [[],[1,"a"]]
Output: [null,true]
Explanation: "a" has never been printed, so it prints.
Example 3
Input: operations = ["Logger","shouldPrintMessage","shouldPrintMessage"], arguments = [[],[1,"x"],[11,"x"]]
Output: [null,true,true]
Explanation: "x" prints at t = 1, and t = 11 is exactly 10 seconds later, so it may print again.
Remember the last time each message was printed. A message prints only if it is new or at least 10 seconds have passed since its last print.
Run checks all cases above. Submit evaluates all test cases.