Google Interview experience
1 round over 3 weeks. No offer, good experience.
Was asked the robot signals problem, made some mistakes while trying to come up with an optimal approach.
Question:You’re receiving signals from a robot, each with a timestamp (sorted in chronological order) and a message. Your task is to print messages that are unique within the last 10 seconds.
Input:
[{timestamp: 2, message: "Ready"}, {timestamp: 4, message: "Ready"}, {timestamp: 9, message: "Go"}, {timestamp: 15, message: "Stop"}]Output: "Ready Go Stop"
Follow-up:
Need to drop duplicates that occur both in the past and the future 10-second window
Input:
[{timestamp: 0, message: "Start"}, {timestamp: 3, message: "Start"}, {timestamp: 5, message: "Move"}, {timestamp: 9, message: "Pause"}, {timestamp: 14, message: "Move"}]Output: "Start Pause"
We can use a hashmap to store the messages as keys and the timestamps as values. Iterate through the list of messages and check whether a message has already been seen and if it falls within the 10-second window.
Know someone interviewing at Google? Pass it on.
Same company, different candidates.
Share yours while it’s fresh. It takes five minutes, it’s anonymous, and it will help future candidates.