← 返回 airbnb 的题目列表Multi-Stream Round-Robin Iterator
类型:online_judge
Problem: Multi-Stream Round-Robin Iterator
Given k byte/char streams (each provided as an iterator), implement a merged iterator MultiStreamIterator that outputs elements in round-robin order:
Each step takes 1 element from the next non-exhausted stream
Once a stream is exhausted, it is skipped in future rounds
Implement:
has_next() -> bool
next() -> byte/char (if no next element exists, raise an exception or return an agreed sentinel)
Constraints
k: 1 ~ 1e5
total elements N: 0 ~ 1e6
Example
Streams:
S1: a b c
S2: d e
S3: f
Output: a d f b e c
Follow-ups
has_next() must not consume elements
Aim for amortized O(1) per next()
Example
Input
3
abc
de
f
Output
adfbec