The Cache With Time Limit interview question asks you to implement a data structure that stores key-value pairs with an expiration time. You need to implement methods for set(key, value, duration), get(key), and count(). If a key is accessed after its duration has passed, it should be treated as non-existent. This Cache With Time Limit coding problem is a practical exercise in asynchronous state management.
Uber, Microsoft, and Confluent use this to evaluate a candidate's familiarity with timers and object-oriented design. It tests whether you can handle overwriting existing keys (and their associated timers) and how you clean up expired data to prevent memory leaks. It’s a very common task in real-world system design for session management and caching.
This doesn't use a specific "LeetCode pattern" but relies on Object-Oriented Design and Timers. You typically use a Map to store the data and a separate mechanism (like setTimeout in JavaScript or a Priority Queue of expiration times in other languages) to invalidate keys.
Practice implementing basic TTL (Time To Live) logic. Understand how your language handles asynchronous tasks—whether it's setTimeout, ScheduledExecutorService, or goroutines. Clean cleanup of resources is a hallmark of a senior engineer.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Word Pattern II | Medium | Solve | |
| Minimum Sum of Squared Difference | Medium | Solve | |
| Detonate the Maximum Bombs | Medium | Solve | |
| Kill Process | Medium | Solve | |
| Largest Divisible Subset | Medium | Solve |