Senior Detailed answer Design DSA & Coding Interviews

How would you design an LRU Cache?

Short answer: Hash map from key → node plus a doubly linked list ordered by recency. get/put are O(1): move accessed node to front; on capacity eviction remove from tail. This is one of the most asked system-design-lite coding questions.

Interview approach

  1. Clarify capacity and that both get and put must be O(1).
  2. Explain why list alone or map alone is not enough.
  3. Implement move-to-front and remove-tail helpers.
  4. Handle update of existing key in put.

Complexity

get/put O(1) average; Space O(capacity).

Common follow-ups

  • LFU Cache
  • Thread-safe LRU
  • TTL expiration

Mistakes to avoid

  • Forgetting to update value on put for existing key
  • Losing list pointers when removing
In C#, LinkedList + Dictionary is the standard interview implementation.
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details