Cache State
Cache is empty — use PUT to add items
How LRU Cache Works
MRUA
←→
B
←→
C
←→
LRUD
Items are in a doubly linked list. MRU at left, LRU at right — evicted first when cache is full.
GET
Hit — found → move to MRU, return value.
Miss — not found → return
Miss — not found → return
-1.
PUT
New key — full? evict LRU → insert at MRU.
Existing — update value → move to MRU.
Existing — update value → move to MRU.
📘 Walkthrough — capacity = 3
PUT 1,A→[1]PUT 2,B→[2→1]PUT 3,C→[3→2→1]GET 1→ HIT →[1→3→2]PUT 4,D→ evict 2 →[4→1→3]Activity Log
liveGraph
Queue / Stack
empty
Visited Order
none yet