Implement a recent-use eviction cache
Company: Snapchat
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 a fixed-capacity key-value cache with a recent-use eviction policy, emphasizing data structure design, state management, and meeting average O(1) time constraints for get and put operations.
Examples
Input: (2, [('put', 1, 10), ('put', 2, 20), ('get', 1), ('put', 3, 30), ('get', 2), ('get', 3)])
Expected Output: [10, -1, 30]
Explanation: Prompt behavior.
Input: (1, [('put', 1, 1), ('put', 1, 2), ('get', 1)])
Expected Output: [2]
Explanation: Update key.
Input: (0, [('put', 1, 1), ('get', 1)])
Expected Output: [-1]
Explanation: Zero capacity edge.