advanced

Design an LRU Cache

Design a least-recently-used cache with O(1) get and put operations. Include capacity management, eviction policy interface supporting LRU/LFU/FIFO, cache statistics tracking, and TTL-based expiration.

Suggested time: 45 minutes

Loading the workspace...

About this problem

An LRU Cache is one of the most frequently asked OOD problems because it combines data structure design (HashMap + doubly-linked list), algorithm correctness (O(1) operations), and concurrency challenges (thread-safe reads that also write). Let's define exactly what the system must do.

What your design needs to cover

  • O(1) Get and Put

  • LRU Eviction

  • Configurable Capacity

  • Pluggable Eviction Policies

Key challenges the editorial covers

Learn from other designs

Related problems

Guides