Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

LFU Cache Implementation

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

Your question is LFU Cache Implementation. 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 LFU (Least Frequently Used) cache template class.

Asked in the Technical Phone Screens (3 rounds) stage. This is a practical C++ coding task focused on data structures and template classes.

For grading, implement lfu_cache(operations, capacity). Each operation is ['put', key, value] or ['get', key]; return the values from get operations, using -1 for missing keys. When frequencies tie, evict the least recently used key.

Constraints

  • 0 <= capacity <= 10^4
  • 1 <= operations.length <= 10^4
  • Each operation is either ['put', key, value] or ['get', key]
  • Keys and values are integers
  • A get for a missing key must return -1
  • When frequency ties occur, evict the least recently used key

Function Signature

def lfu_cache(operations, capacity):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output