Loading...

The Eviction Policy

A medium Python interview practice problem on DataDriven. Write and execute real python code with instant grading.

Domain
Python
Difficulty
medium
Seniority
mid

Problem

Our query result cache needs an LRU eviction policy. Build a class called LRUCache with a fixed capacity. get(key) returns the value or -1 if absent. put(key, value) inserts or updates. When full, evict the least recently used entry. Both get and put count as 'use'.

Practice This Problem

Solve this Python problem with real code execution. DataDriven runs your Python code in a sandboxed Docker environment and grades it instantly.