Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

LRU Cache for Audio Segments

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

Your question is LRU Cache for Audio Segments. 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 (Least Recently Used) cache for audio segments. Design a class LRUCache with integer capacity and methods get(segment_id) and put(segment_id, data). get returns the stored segment data if present, otherwise -1. When inserting into a full cache, evict the least recently used segment. Both operations must run in O(1) average time.

Constraints

  • 1 <= capacity <= 10^5
  • 0 <= segment_id <= 10^9
  • 0 <= data <= 10^9
  • At most 2 * 10^5 calls to get and put
  • get and put should run in O(1) average time

Function Signature

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