Level: Mid-Level
Round: Phone Screen · Type: Coding · Difficulty: 6/10 · Duration: 60 min · Interviewer: Unfriendly
Topics: Hash Map, LRU Cache, System Design
Location: Los Gatos, CA
Interview date: 2025-02-15
I had a technical phone screen where I was asked to implement a function that prints events, but only once within a 1-minute window. The input events have a name and a timestamp.
The coding question I received was:
Implement a print function. The input consists of events, each with a name and timestamp. If an event with the same name occurs within 1 minute, print it only once.
I initially used a hash map to store the event names and their timestamps. When a new event arrives, I check if the last time I saw this event was more than 1 minute ago. If so, I print the event; otherwise, I ignore it.
We then discussed how to remove expired data from the hash map, considering approaches like LRU cache, lazy deletion, or a cron job for periodic cleanup. I was also asked how to maintain the LRU cache if the event timestamps were out of order.