Google | L4 | India | Onsite | DSA | Round 1

Anonymous User
2672
Jun 02, 2025

Problem Statement
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 to make them more readable is to remove the 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

Solution
I gave simple hashmap approach where we will check incoming message timestamp with current timestamp and display message accordingly
Also, we will update current string timestamp in hashmap

Follow up
Will the code work in production without any issues?

I was not able to pinpoint the issue until he told me what if billions of requests are coming

Solution
I told for many requests hashmap will reach its size limit
So we need to remove stale entries from hashmap
Gave linear solution first to iterate over all keys in hashmap and remove if need to be deleted
Then said myself that we can use deque to remove from front until current message is in window time
He said ok and asked to write the code
In the end he said it looks good after I did a dry run

Initially he said there will be 1 warmup and 1 followup question and interview was of 45 minutes
Do you think I completed the entire interview or this was the warmpup question only?

Comments (9)