Implement an LRU cache
Company: Oracle
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Quick Answer: This question evaluates a candidate's ability to design and implement efficient data structures that meet strict O(1) time constraints while managing access-based eviction policies, testing competencies in algorithmic reasoning, state management, and performance trade-offs.
Constraints
- Inputs are provided as Python literals matching the function signature.
- Return a deterministic exact-match result.
Examples
Input: (2, [['put',1,1], ['put',2,2], ['get',1], ['put',3,3], ['get',2], ['put',4,4], ['get',1], ['get',3], ['get',4]])
Expected Output: [None, None, 1, None, -1, None, -1, 3, 4]
Explanation: Eviction sequence.
Input: (1, [['put',2,1], ['put',2,2], ['get',2], ['put',3,3], ['get',2]])
Expected Output: [None, None, 2, None, -1]
Explanation: Update existing key.
Hints
- Choose a representation that makes the core operation simple.
- Handle empty and boundary inputs before the main algorithm.