Design a logger system that receive stream of messages along with its timestamps, each message should be printed if and only if it is not printed in the last 10 seconds.
Given a message and a timestamp (in seconds granularity), return true if the message should be printed in the given timestamp, otherwise returns false.
It is possible that several messages arrive roughly at the same time.
We need to track the last printed timestamp for each message. By using a hash map to store the last timestamp for each message, we can efficiently check if a message should be printed (i.e., if it hasn’t been printed in the last 10 seconds).
Use a hash map to store the last printed timestamp for each message.
For each incoming message and timestamp:
If the message is not in the map or the difference between the current timestamp and the last printed timestamp is at least 10, print the message and update the timestamp.
Otherwise, do not print the message.
Return true if the message should be printed, false otherwise.