Back to problems

LRU Cache with TTL

Object-Oriented Programming · ByteDance · Medium

Build an LRU cache in which every stored entry has its own time-to-live (TTL), expressed in seconds. The cache must provide these operations: put(key, value, ttl) stores value under key for ttl seconds. When the cache is full, remove the least recently used entry, or remove expired entries as needed. get(key) returns the value associated with key. Return -1 when the key is absent or its entry has expired. The cache can hold at most capacity entries. Use the following…

Checking your access…