LRU Cache

Total Accepted: 36778 Total Submissions: 248361 My Submissions

Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and set.

get(key) - Get the value (will always be positive) of the key if the key exists in the cache, otherwise return -1.
set(key, value) - Set or insert the value if the key is not already present. When the cache reached its capacity, it should invalidate the least recently used item before inserting a new item.

Show Tags
Data Structure
Have you met this question in a real interview?
When did you meet this question?
1 week ago
1 month ago
3 months ago
6 months ago
More than 6 months ago
How long have you been interviewing?
Not yet started
1 month
3 months
6 months
More than 6 months


You have not signed in, cannot submit your code.
Submit failed, try again please.

Submission Result: {[{ statusText }]}More Details

Share your acceptance!

Runtime Error Message: {[{ runtimeError }]}
Last executed input: {[{ lastExecutedTestCase }]}
{[{ resultCodeOutput }]}
Input: {[{ resultWaTestCaseInput }]}
Output: {[{ resultWaTestCaseOutput }]}
Expected: {[{ resultWaTestCaseExpected }]}

Send Feedback