Auto Saved.

146. LRU Cache

Please login first.
My Submissions
  • Total Accepted: 89102
  • Total Submissions: 561944
  • Difficulty: Hard

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.

Subscribe to see which companies asked this question

Show Tags
Design
Have you met this question in a real interview?
Yes
No
When did you meet this question?
last week
last month
last 3 month
last 6 month
more than 6 months
other
Which company asked you this question?
Adobe
Airbnb
Alation
Alibaba
Amazon
Apple
Arista
Baidu
Blend Labs
Blizzard
Bloomberg
Box
Bungie
Cisco
Conviva
Coursera
CreditEase
Deutsche Bank
Dropbox
eBay
Electronic Arts
EMC
Epic Systems
Expedia
Facebook
Flipkart
Fortinet
FreeWheel
Goldman Sachs
Google
GrabTaxi
Groupon
Hedvig
Hulu
Intel
Jane Street
JPMorgan
Jump Trading
Lending Club
LinkedIn
LiveRamp
Marvel
Matlab
McKesson
Microsoft
Morgan Stanley
Nvidia
Oracle
Orbitz
Palantir
Paypal
Pinterest
Pocket Gems
Qualtrics
Qumulo
Quora
Rackspace
Salesforce
Sina
Snapchat
Square
Sumologic
Symantec
Tencent
TinyCo
Tradeshift
TripAdvisor
Twitter
Two Sigma
Uber
VMware
Walmart
Yahoo
Yandex
Yelp
Zenefits
Zynga

Discuss Pick One


Send Feedback