← All problems
LRU Cache (hashmap + list drill)
Design an LRU cache supporting O(1) get and put with a capacity limit; when the capacity is exceeded, evict the least recently used entry. Combine a hash map with a doubly linked list.
Complexity
Time O(1), Space O(capacity)
Common pitfalls
- Singly linked list (can't evict in O(1))
- Forgetting to update map on eviction
Your solution
Log in to save your code and track progress.