PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/Amazon

Implement streaming k-way merge with constraints

Last updated: Mar 29, 2026

Quick Overview

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.

  • Medium
  • Amazon
  • Coding & Algorithms
  • Data Scientist

Implement streaming k-way merge with constraints

Company: Amazon

Role: Data Scientist

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Onsite

Implement a function merge_k(iterators, N) that returns the first N items of the global ascending order from k sorted, potentially unbounded iterators of integers. Constraints: iterators may block, memory must be O(k), and duplicates must be preserved but made stable by source index (stable tie-breaker). Specify time complexity, show how you would handle iterator exhaustion, and discuss how to add deduplication (unique-only) without increasing asymptotic complexity. Provide unit tests that cover k=1, empty streams, large N, and pathological inputs (e.g., one iterator far slower than the rest).

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.

Related Interview Questions

  • Find Unique Target-Sum Pairs - Amazon (easy)
  • Find Valid IP Addresses in Files - Amazon (medium)
  • Implement Optimal Bucket Batching - Amazon (hard)
  • Implement Cache and Rotate Matrix - Amazon (medium)
  • Find Longest Activatable Server Streak - Amazon (hard)
Amazon logo
Amazon
Oct 13, 2025, 9:49 PM
Data Scientist
Onsite
Coding & Algorithms
3
0

Implement a function merge_k(iterators, N) that returns the first N items of the global ascending order from k sorted, potentially unbounded iterators of integers. Constraints: iterators may block, memory must be O(k), and duplicates must be preserved but made stable by source index (stable tie-breaker). Specify time complexity, show how you would handle iterator exhaustion, and discuss how to add deduplication (unique-only) without increasing asymptotic complexity. Provide unit tests that cover k=1, empty streams, large N, and pathological inputs (e.g., one iterator far slower than the rest).

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Amazon•More Data Scientist•Amazon Data Scientist•Amazon Coding & Algorithms•Data Scientist Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.