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
- Clarify capacity and that both get and put must be O(1).
- Explain why list alone or map alone is not enough.
- Implement move-to-front and remove-tail helpers.
- 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.
Share this Q&A
Share preview image: https://www.toolliyo.com/images/toolliyo-logo.png