AlgoMaster Logo

LRU Cache

capacity=2,operations=[put(1,1), put(2,2), get(1), put(3,3), get(2), put(4,4), get(1), get(3), get(4)]
0 / 45
LRUCache(2)put(1, 1)put(2, 2)get(1) = ?put(3, 3)get(2) = ?put(4, 4)get(1) = ?get(3) = ?get(4) = ?size 0 / 2MRUmap(empty)hash map for O(1) lookup + doubly linked list for recency
algomaster.io
Step:LRU Cache initialized with capacity 2: a hash map for O(1) lookup + a doubly linked list for recency order.