Google Interview Questions
Company: Google
Role: unknown
Interview Stage: Phone Screen
Location: unknown
Year: unknown
Original Post Content:
I have appeared for google interview.
1st round - screening round
2nd round - coding round
they asked me this question in 2nd round
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
it was an easy problem but I was trying to give approach only, but didn't write the code as interviewer was not okay with the approach.
It was an easy HashMap question where we just need to store message as key and timestamp as value.
If message is not present in hashmap return true and print the message and store the message in hashmap,
and then
find last timestamp of that message in HashMap. If timestamp - last timestamp > threshold time then return true and print the message and store the message, else return false and do not store message.
I was cleared with this, but interviewer didn't ask to write code.
And maybe I lost the opportunity this time.
Because I didn't write code. Let's see what will be the result.