Design a single-machine LRU cache
Company: DoorDash
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: Medium
Interview Round: Technical Screen
Quick Answer: This question evaluates a candidate's ability to design an efficient in-memory LRU cache and apply concurrency control, covering eviction semantics, capacity management, key updates, and synchronization for thread safety.
Examples
Input: (2, [('put', 1, 1), ('put', 2, 2), ('get', 1), ('put', 3, 3), ('get', 2), ('get', 3)])
Expected Output: [1, -1, 3]
Explanation: Evicts least recently used.
Input: (0, [('put', 1, 1), ('get', 1)])
Expected Output: [-1]
Explanation: Zero capacity.
Input: (1, [('put', 1, 1), ('put', 1, 2), ('get', 1)])
Expected Output: [2]
Explanation: Update existing key.