Merge Regional Listing Feeds Into One Newest-First Stream

Last updated: November 29, 2026

Quick Overview

Implement an iterator that takes several shard iterators, each yielding (updated_at, listing_id) sorted newest first, and yields a single newest-first stream that emits each listing id only once, at its most recent update.

eBay
Coding & Algorithms
Software Engineer
eBay
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

0

0 solved


Implement an iterator that takes several shard iterators, each yielding (updated_at, listing_id) sorted newest first, and yields a single newest-first stream that emits each listing id only once, at its most recent update.

eBay stores listings across many shards and regions, and services like a seller's activity page or a recently updated feed must merge them lazily. The interviewer checks a k-way merge with a heap, a proper Python iterator, and that you never load a whole shard into memory.

What the Interviewer Expects
  • Seed a heap with the head of each shard
  • Pop the newest, then advance only that shard
  • Implement __iter__ and __next__ and raise StopIteration
  • Deduplicate by listing id, keeping the first (newest) occurrence
  • O(log k) per emitted item
Key Topics to Cover
k-way merge
heap
iterator protocol
streams
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
  • The seen set grows without bound. How would you bound memory?
  • How would you resume the feed from a cursor after a page boundary?
  • What if one shard is slow or times out?
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

Each shard yields (updated_at, listing_id) in non-increasing updated_at. The merged output is non-increasing too. A listing can appear in several shards (for example after a migration) or several ...

High-Level Design

Classic k-way merge. The heap holds at most one pending item per shard, keyed by negated timestamp so the newest is on top. After popping an item, pull the next item from that same shard. Because the ...


Submit Your Answer
Markdown supported