Implement an in-memory TTL cache (optionally LRU)
Asked at OpenAI · Coding Questions · Difficulty: Medium · Last asked Apr 22, 2026
Build an in-memory key-value cache in which every entry expires a fixed time after it was written. The cache can also have a maximum capacity: when it is full, the entry that was used least recently is dropped. Time is passed in explicitly as `now_ms` (milliseconds) so the behavior is deterministic and easy to test.
Loading the problem…