Design a LRU Cache
Last updated: June 17, 2026
Quick Overview
Implement a Least Recently Used cache with O(1) get and put operations. Requires combining a hash map with a doubly linked list. A Google classic.
Google
Coding & Algorithms
Software Engineer
Software Engineer
Phone Screen
Coding & Algorithms
Medium
200
0
118 solved
Implement a Least Recently Used cache with O(1) get and put operations. Requires combining a hash map with a doubly linked list. A Google classic.
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Problem Analysis
This problem requires implementing an LRU (Least Recently Used) cache, which means we need to efficiently track the order of item usage. The key operations are get and put, which must both run in ...
Approach
- Data Structures: Use a hash map to store keys and their corresponding nodes in the doubly linked list. Each node will hold the key and value. The doubly linked list allows for efficient inserti...
Submit Your Answer
Markdown supported