I had a technical phone screen where I was asked a coding question involving implementing a time-limited cache.
Details
The coding question I got was:
LeetCode 2622. Cache With Time Limit
Follow up: How would you clean up expired data?
My approach:
First, I implemented the basic cache functionality using a dictionary to store the key-value pairs and their expiration times.
Then, for the follow-up, I discussed using a background thread or a scheduled task to periodically iterate through the cache and remove expired entries.
Key insights:
Understanding the trade-offs between different approaches for cleaning up expired data (e.g., background thread vs. scheduled task).
Considering the concurrency implications of accessing and modifying the cache from multiple threads.