← 返回 oracle 的题目列表LRU Cache with Expiration (LC 146 + TTL)
类型:qbank
Implement an O(1) LRU cache with a hash map plus doubly linked list, then extend it with per-entry expiration so expired keys read as absent.
Requirements
Implement an LRU cache supporting get(key) and put(key, value) in O(1) average time.
Standard structure: a hash map for key→node lookup plus a doubly linked list ordering nodes by recency.
Follow-up: extend the cache to support per-entry expiration (TTL). An expired entry must be treated as absent on get, even if it has not yet been evicted by capacity.
Notes
The base is equivalent to LeetCode 146. The expiration follow-up is the discriminator and is where time tends to run out — be ready to contrast lazy expiration (check the timestamp on access) with active eviction before writing it.