LRU Cache for Query Results
Updated
Problem statement
Maintain a cache with positive integer capacity. Process each operation atomically in the supplied completed serialization order:
[1, key]performsget(key). Return the stored value, or-1when the key is absent. A successful get makes the key most recently used.[2, key, value]performsput(key, value). Insert or update the key and make it most recently used. Updating an existing key does not change the cache size. If an insertion exceeds capacity, evict exactly the least recently used key.
Return one string per operation: the decimal result of each get and the literal string "null" for each put. Implement both operations in O(1) expected time.
The problem statement continues
ProExamples
Example 1
capacity = 2operations = [[2,1,10],[2,2,20],[1,1],[2,3,30],[1,2],[1,3]]return = ["null","null","10","null","-1","30"]Reading key 1 makes it recent, so inserting key 3 evicts key 2.
Original screenshot from the interview report
ProFastPrep Pro
Reported in 1 Amazon interview this weekUnlock this recently reported problem
FastPrep Pro gives you full access to interview problems reported within the last week.
- Full problem statement and constraints
- 1 more worked example, explained
- Guided hints and editorial
- Run your code on real test cases
$8.25/month
$99 billed yearly — or $19 month-to-month. Cancel anytime.
Free plan — 2 of 2 free unlocks used this week
More Amazon Phone Screen questions
- Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Course Schedule IIPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Minimum Time to Spread Through a GridPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Consistent-Hash Packet RouterPHONE SCREEN · Seen Nov 2026
- Count Connected ComponentsPHONE SCREEN · Seen Nov 2026
- Second Largest Distinct ElementPHONE SCREEN · Seen Nov 2026
- Task SchedulerOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Top K Frequent ElementsOA · PHONE SCREEN · Seen Nov 2026
- Number of IslandsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- 3SumPHONE SCREEN · Seen Nov 2026
Similar questions at other companies
- LRU CacheServiceNow · PHONE SCREEN · ONSITE INTERVIEWServiceNow interview questions
- LRU Key-Value Cache OperationsCohesity · PHONE SCREEN
- Least Recently Used CacheMicrosoft · OA · PHONE SCREEN · ONSITE INTERVIEWMicrosoft interview questions
- LRU CacheAMD · ONSITE INTERVIEWAMD interview questions
- LRU CacheApple · PHONE SCREEN · ONSITE INTERVIEWApple interview questions
- Least Recently Used CacheByteDance · PHONE SCREEN · ONSITE INTERVIEWByteDance interview questions
- LRU CacheCoupang · PHONE SCREEN
- LRU Cache with Hit and Miss CountersLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
- Least Recently Used CacheGoldman Sachs · ONSITE INTERVIEWGoldman Sachs interview questions
- LRU CacheBlinkit · PHONE SCREENBlinkit interview questions
Interview reports that mention this question
- Amazon Experienced SDE Onsite Questions: 1 Experience
- Amazon Experienced Hire OA and Interviews: 21 Experiences
- Amazon Full-Time Interview Timelines: 9 Experiences (Part 2 of 2)
- Amazon Full-Time SDE Interviews: 9 Experiences (Part 1 of 2)
- Amazon Frontend Spring 2025 Loops: 11 Experiences (Part 2 of 2)
- Amazon Frontend Engineer Interviews: 21 Experiences (Part 1 of 2)