Back to problems

LRU Cache + Thread-Safe Follow-up

Object-Oriented Programming · LinkedIn · Hard

Design a data structure that implements a least-recently-used (LRU) cache with a fixed capacity. The cache must support two operations, both running in $$O(1)$$ amortized time: get(key) — retrieves the value associated with key. If the key exists, this access marks the entry as the most recently used and returns its value. If the key is absent, return -1. put(key, value) — inserts key with the given value. If the key already exists, update its value and mark it as most…

Checking your access…