Round-Robin Iterator Interleaving Multiple Activity Feed Sources
Last updated: November 29, 2026
Quick Overview
Given several ordered sources (for example Outlook, Teams and SharePoint activity lists), build an iterator that returns one item from each non-empty source in turn until all sources are exhausted.
Microsoft
November 29, 20260
0
0 solved
Given several ordered sources (for example Outlook, Teams and SharePoint activity lists), build an iterator that returns one item from each non-empty source in turn until all sources are exhausted.
A Microsoft phone screen question in the zigzag iterator family, tied to merging activity feeds in Microsoft 365. The interviewer looks for a queue of iterators that drops exhausted sources and works for any number of sources.
What the Interviewer Expects
- Generalize from two sources to k sources
- Use a queue that only contains non-empty sources
- Make next O(1)
- Handle sources that are empty from the start
- Keep has_next cheap and side effect free
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you weight sources so Teams items appear twice as often?
- How would you merge by timestamp instead of round-robin?
- How would you make this thread safe for concurrent consumers?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input: a list of iterables.
next()returns the next item in round-robin order, skipping exhausted sources.has_next()reports whether any item remains.- Sources may be lazy iterables, so do...
High-Level Design
Keep a deque of (head_value, iterator) pairs for sources that still have at least one item. Pre-fetching each source's head means a source sits in the queue only if it is non-empty, which makes `has...