Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Design an LRU Cache

MediumPython00:00
I
Practice interviewer
Your interviewer
In session
I
Interviewer

Welcome to the Python screen.

The question is on your right: Design an LRU Cache. Read through the requirements first.

Run and submit your code as often as you need. You also have five interviewer messages this session - want to talk through your approach, or are you ready to start coding?

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