Round Robin Iterator Merging Multiple Feed Sources
Last updated: November 29, 2026
Quick Overview
Build an iterator that takes several feed sources (each an iterator of posts, possibly unbounded or of different lengths) and yields posts in round-robin order, skipping exhausted sources, with hasNext and next methods.
0
0
0 solved
Build an iterator that takes several feed sources (each an iterator of posts, possibly unbounded or of different lengths) and yields posts in round-robin order, skipping exhausted sources, with hasNext and next methods.
The LinkedIn feed blends candidates from many sources (network posts, follows, ads, recommendations) before ranking. This screen question checks iterator protocol design, lazy consumption, and a queue of active sources.
What the Interviewer Expects
- Keeps a queue of iterators that still have elements
- Uses a one-element lookahead per source so hasNext is accurate without consuming
- Never materializes the sources into lists
- Removes exhausted sources in O(1)
- Raises StopIteration or an error on next when empty
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, for example two network posts per ad?
- How do you make this work when sources are async network calls?
- How would you dedupe the same post appearing in two sources?
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 Python iterables. has_next() returns whether any element remains. next() returns the next element from the current source and moves that source to the back of the queue. Sources m...
High-Level Design
Wrap each source with a lookahead: pull its first element at construction; if none, drop it. The deque holds (iterator, buffered_value) pairs. next() pops the front pair, returns its buffered valu...