The Forgetful Machine
A medium Python mock interview question on DataDriven, with an AI interviewer who asks follow-up questions and a hire or no-hire decision at the end.
- Domain
- Python
- Difficulty
- medium
- Seniority
- L5
Interview Prompt
We need a fixed-size in-memory cache that holds at most `capacity` entries, where `get(key)` returns the stored value or -1 if the key isn't present and `put(key, value)` inserts or updates an entry, evicting the least recently used entry when the cache is full. Implement that cache as `LRUCache`, then a driver that builds one cache, replays each operation in `ops` (`['get', k]` or `['put', k, v]`), and returns the values produced by the get operations in the order they ran.
Summary
It remembers everything, until it does not.
How This Interview Works
- Read the vague prompt (just like a real interview)
- Ask clarifying questions to the AI interviewer
- Write and run your Python against test cases
- Answer the interviewer's follow-up questions, then get a hire or no-hire decision