Round-Robin Iterator That Interleaves K Seller Offer Feeds

Last updated: November 29, 2026

Quick Overview

Given k iterators over seller offer feeds of different lengths, build an iterator that returns one offer from each feed in turn, skipping feeds that have run out.

Amazon
Coding & Algorithms
Software Engineer
Amazon
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

0

0

0 solved


Given k iterators over seller offer feeds of different lengths, build an iterator that returns one offer from each feed in turn, skipping feeds that have run out.

The Amazon offer listing page blends offers from many sellers fairly, which motivates round-robin interleaving. Interviewers check that you avoid scanning exhausted feeds repeatedly and that the iterator is lazy.

What the Interviewer Expects
  • Use a queue of active iterators
  • Pop a feed, take one item, re-enqueue if it still has items
  • Never materialize all items up front
  • O(1) amortized per next call
  • Handle empty feeds at construction
Key Topics to Cover
iterators
queues
round robin
lazy evaluation
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
  • How would you weight sellers so a feed with weight 2 gets two items per round?
  • How would you make this a Python generator?
  • What if a feed is a remote stream that can block?
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 k Python iterables. Output: an object with has_next() and next() that yields items in order feed 0 item 0, feed 1 item 0, ..., feed 0 item 1, and so on, skipping exhausted feeds. ...

High-Level Design

Wrap each iterable with a one-item lookahead so we can tell whether it is exhausted without losing an item. Place every non-empty wrapped feed in a deque. next() pops the left feed, takes its curren...


Submit Your Answer
Markdown supported