Level: Senior-Level
Round: Phone Screen · Type: Coding · Difficulty: 6/10 · Duration: 60 min · Interviewer: Unfriendly
Topics: Cache, System Design, LRU Cache, Data Structures
Location: Los Gatos, CA
Interview date: 2025-03-25
Got offer: False
I had a technical phone screen where I was asked to design an auto-expiring cache similar to LeetCode 2622. The prompt was text-based, and I had to discuss the implementation details with the interviewer. I implemented the APIs, discussed input types, and cache miss scenarios.
The coding question I got was:
`python class AutoExpireCache: def init(self):
def set(self, key, value, timestamp, expire_period):
def get(self, key):
`
My approach:
set and get APIs using a dictionary.None instead of False for cache misses (returning None is better because False can be a valid value).assert in Python to verify the functionality.Follow-up 1:
What if memory is insufficient?
I mentioned cron jobs and lazy deletion, as I had seen in commonly asked interview questions. We discussed these approaches, but I wasn't asked to write code for them.
Follow-up 2:
What if memory is still insufficient?
I realized the interviewer wanted me to implement a sized LRU cache. I initially used a dictionary and didn't realize I could use an OrderedDict. Due to time constraints, I didn't complete the implementation.
LeetCode similar: LeetCode 2622