Round-Robin Iterator That Interleaves Multiple Feed Candidate Sources

Last updated: November 29, 2026

Quick Overview

The feed mixer pulls candidates from several sources (following, interest-based, trending, LIVE), each exposed as an iterator that may be finite or infinite. Implement an iterator with `has_next()` and `next()` that yields one item from each live source in turn and skips sources once they are exhausted.

TikTok
Coding & Algorithms
Software Engineer
TikTok
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


The feed mixer pulls candidates from several sources (following, interest-based, trending, LIVE), each exposed as an iterator that may be finite or infinite. Implement an iterator with `has_next()` and `next()` that yields one item from each live source in turn and skips sources once they are exhausted.

TikTok's feed blends many candidate generators, and iterator design questions like this appear in technical screens to test API thinking. The interviewer checks lazy evaluation that works with infinite sources, a correct idempotent `has_next`, and no confusion when items are falsy values such as 0 or None.

What the Interviewer Expects
  • Uses a queue of iterators so exhausted sources drop out in O(1)
  • Never materializes a source, so infinite generators work
  • Makes has_next idempotent with a one-item lookahead buffer
  • Uses a sentinel object so None and 0 are valid items
  • Follows Python's iterator protocol
Key Topics to Cover
iterators
lazy evaluation
queues
API design
sentinel values
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Sources now have weights, such as 3 interest items per trending item; how do you change it?
  • How would you deduplicate a video that appears in two sources?
  • One source is slow (a network call); how would you avoid blocking the feed?
  • How would you add a remove_source(name) operation?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input: a list of iterables, any of which can be infinite. Output order: first item of source 1, first of source 2, and so on, cycling, skipping sources that have run out. has_next() can be called an...

High-Level Design

Keep a deque of live iterators and a one-item buffer. To fill the buffer, pop the front iterator and ask for its next item with a sentinel default. If it yields, store the item and push the iterator t...


Submit Your Answer
Markdown supported