Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Design an LRU Cache
00:00
5 left

Design an LRU Cache

EasyPython

Problem

Implement an LRU cache with fixed capacity. Support get(key) and put(key, value) so that both run in O(1) average time, and evict the least recently used key when the cache is full.

Constraints

  • 1 <= capacity <= 3000
  • 0 <= key <= 10^4
  • 0 <= value <= 10^5
  • Up to 2 * 10^5 operations
Interviewer

Your question is Design an LRU Cache. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.