← All problems

LRU Cache (hashmap + list drill)

Medium hash mapslinked listsdesign LeetCode ↗
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.

Hints (0/3 revealed)

Log in to reveal hints progressively.

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.