Implement streaming k-way merge with constraints
Company: Amazon
Role: Data Scientist
Category: Coding & Algorithms
Difficulty: Medium
Interview Round: Onsite
Quick Answer: This question evaluates competence in streaming algorithms and resource-constrained algorithm design, specifically implementing a k-way merge over blocking, potentially unbounded integer iterators while preserving stable duplicates and reasoning about time and O(k) space complexity.
Constraints
- Inputs are Python literals matching the function signature.
- Return a deterministic exact-match value.
Examples
Input: ([[1,4,7],[1,3,5],[2,6]], 6)
Expected Output: [1, 1, 2, 3, 4, 5]
Explanation: Tie broken by source index while preserving duplicates.
Input: ([[], [2,3]], 5)
Expected Output: [2, 3]
Explanation: Empty stream.
Input: ([[1,2,3]], 2)
Expected Output: [1, 2]
Explanation: Single stream.
Hints
- Choose a representation that makes the requested operation direct.
- Handle empty inputs and boundary cases first.