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
Google
June 17, 2026
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
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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
  1. 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

Related Questions