Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Design an LRU Cache

MediumPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Design an LRU Cache. Start with the requirements on the right.

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.

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
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output