Implement cache and merge intervals
Company: Microsoft
Role: Machine Learning Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
Quick Answer: This question evaluates proficiency in designing and implementing efficient data structures (a fixed-capacity LRU key-value cache) and interval-processing algorithms (merging overlapping closed intervals), emphasizing time-complexity constraints, correct state management, and robustness to edge cases within the Coding & Algorithms category.
LRU Cache Operation Simulation
Constraints
- Inputs are Python literals matching the function signature.
- Return a deterministic exact-match value.
Examples
Input: (2, [['put',1,1],['put',2,2],['get',1],['put',3,3],['get',2],['get',3]])
Expected Output: [None, None, 1, None, -1, 3]
Explanation: Evict least recently used key.
Input: (1, [['put',1,1],['put',1,2],['get',1]])
Expected Output: [None, None, 2]
Explanation: Updating key refreshes it.
Hints
- Model object-style prompts as operation streams when needed.
- Handle empty and boundary cases before the main logic.
Merge Closed Intervals
Constraints
- Inputs are Python literals matching the function signature.
- Return a deterministic exact-match value.
Examples
Input: ([[1,3],[2,6],[8,10],[15,18]],)
Expected Output: [[1, 6], [8, 10], [15, 18]]
Explanation: Prompt example.
Input: ([[1,4],[4,5]],)
Expected Output: [[1, 5]]
Explanation: Closed intervals touching overlap.
Input: ([],)
Expected Output: []
Explanation: No intervals.
Hints
- Model object-style prompts as operation streams when needed.
- Handle empty and boundary cases before the main logic.