Skip to content
LakeBench
ProblemsCommunityPricing
Sign inStart practicing

A simple LRU-style access cache

Python data engineering interview problem. Difficulty: advanced. Pattern: Hashing. About 20 minutes. Part of the Pro drill bank.

A hot key-value cache for SKU lookups should evict the least recently used entry when it hits capacity, the same policy as many production caches.

Simulate an LRU cache: get/put operations with a capacity, returning the state the tests expect.

Requirements

  • A get refreshes recency.
  • A put on a full cache evicts the least recently used key.

Constraints

  • cap: integer capacity.
  • ops: a sequence of cache operations.
  • Capacity can be 1.

Examples

Input: lru_run(2, [['put', 1, 'a'], ['put', 2, 'b'], ['get', 1], ['put', 3, 'c'], ['get', 2], ['get', 3]]) Output: ['a', None, 'c'] This input follows the stated rules and produces this output.

Topics: lakebench, python, OOP.

More Python interview questions · All interview problems · Learn data engineering

advanced

A simple LRU-style access cache

Interview-style drill: Implement a fixed-capacity cache that evicts the least recently accessed key.

Simulate an LRU cache: get/put operations with a capacity, returning the state the tests expect.