Imagine you have a robot that sends status messages that humans will read in real time. The raw messages are hard to read for a human because there are often many messages produced in short periods of time. One idea is to make them more readable is to remove duplicate messages over a 10 second window.
Design and implement a program to hide duplicates of any message that has already been displayed within the past 10 seconds.
Example Messages Received, with Timestamps:
10 solar panel activated
11 low battery warning
12 tire one: low air pressure
13 solar panel activated
14 low battery warning
21 solar panel activated
35 solar panel activated
Example Messages Shown to User:
10 solar panel activated
11 low battery warning
12 tire one: low air pressure
21 solar panel activated
35 solar panel activated
From experience operating the robot, users have determined that there is a bug in the robot and duplicate messages are not to be trusted at all, and duplicate messages should be completely removed from the output if they occur within 10 seconds. Design and implement a program to completely remove the duplicate messages.
This problem asks you to filter a real-time message stream so that any message already shown within the past 10 seconds is suppressed. A standard solution is to keep a hash map from message text to the last timestamp it was displayed, then process messages in order and output only those whose previous display time is at least 10 seconds earlier. The sample demonstrates how repeated robot status messages are hidden until the window has expired.