Deep Dive

LRU Cache

146. LRU Cache · Design · 78 of 78

1/8

A cache with a limit

ABCD
In this lessonStep 1 of 8 · ← → keys
The question

Build a cache with a size limit where get and put both take O(1). When it's full, remove the entry used least recently. A hash map gives fast lookup; a doubly linked list keeps the order of use.