AO
Back

Ordered, Multiples and Merged Integer Streams

Also reported as OrderedIntStream · MultiplesStream · MergeStream

Phone ScreenPhone ScreenLast reported February 2026Low Frequency

Problem Overview

The round: one Sierra phone screen report. Three coding parts on streams of ints. You write and run your own tests. The interviewer said there are no follow-ups beyond the three parts, and only said "ok, next part" between them. The candidate finished the code and could run their tests, and was later rejected with no reason given. Separately, they wondered whether their tests had been complete. Three graded parts.

Interface and rules (ours)

The report gives one short line per part: the class name and what it outputs. Everything below, from the method names to the rules in each part, is our reading of those lines. Confirm each rule with the interviewer. Here every stream has the same two methods:

def has_next(self) -> bool: ...   # True if next() has a value; does not consume it
def next(self) -> int: ...        # the next value; raises StopIteration when empty

Part 1 — OrderedIntStream over a list

class OrderedIntStream:
    def __init__(self, nums: list[int]): ...
  • Outputs the ints of nums in order, one per next() call. Here "in order" means ascending: the constructor sorts a copy. If the list is already sorted, emitting it as given is the same thing.
  • Duplicates and negatives are kept. An empty list is an empty stream.

Part 2 — MultiplesStream of an int

class MultiplesStream:
    def __init__(self, k: int): ...
  • Outputs the multiples of k in order: k, 2k, 3k, .... It never ends, so has_next() is always True.
  • k must be a positive int; anything else raises ValueError.

Part 3 — MergeStream of a list of streams

class MergeStream:
    def __init__(self, streams: list, unique: bool = False): ...
  • Outputs every value of the input streams in ascending order, like the merge step of merge sort. Each input is any object with has_next() and next(): an OrderedIntStream, a MultiplesStream, or another MergeStream.
  • Inputs can be infinite, so the merge must stay lazy: never read a whole stream ahead.
  • Duplicates are kept by default (6 comes out twice when merging multiples of 2 and 3). unique=True is the other reading: a value equal to the one before it is dropped.

Notes: the report's wording is short. These are ours: the method names, StopIteration, sorting a copy in Part 1, starting Part 2 at k (not 0) and the ValueError rule, and in Part 3 keeping duplicates, the unique flag, supporting infinite and nested inputs. Ask about each before coding.

What Reports Emphasize

What the report says: three short parts and no follow-ups; the interviewer said to read the problem carefully and write it. You write and run your own tests. The candidate finished the code and was later rejected with no reason; separately, they wondered whether their tests had been complete.

Common mistakes (ours, not reported): has_next() that consumes a value; draining an input stream inside the merge, which hangs on an infinite stream; pushing (value, stream) onto the heap so equal values compare streams; storing every multiple in a list; testing only the happy path.

Edge cases to test (ours): an empty list; has_next() called twice; next() after the end; duplicates and negatives; an infinite input to the merge; duplicates across merged streams; a merge of no streams; a merge used as an input to another merge.

Alternative approaches (ours): the Python iterator protocol (iter and next) instead of has_next() and next(); for two inputs, a two-pointer merge with one buffered head per stream instead of a heap.

Practice

Write your own against 14 test cases, or read the worked solution — approach, complexity, and code that runs.
Did this match your interview?

If you have had this round, tell us how close this page was. It is how we keep the pages accurate.

Sierra AI · Phone Screen · Reported 1× across candidate reports
Is this helpful?