FastPrepRound-Robin Iterator over Iterators
Problems/Round-Robin Iterator over Iterators

Round-Robin Iterator over Iterators

Bridge logoBridge● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Bridge, the Stripe-owned stablecoin company, asked this in an onsite coding round. The question grew in steps: first a plain iterator, then one built on top of other iterators, and finally a single iterator that walks several source iterators in rotation. It takes one value from a source on its turn and passes over any source that is already used up.

The report described only the third part in detail and gave no interface, element type, limits or examples. Our choices here: the iterators are given as lists of integers from -1000 to 1000. The round-robin iterator is driven by a list of next and hasNext operations with one string result each. Turns go in index order starting from the first iterator. Empty iterators are skipped from the start. Next is only called while an element remains. There are at most 1000 elements in total and 2000 operations.

Our version is about 85% the same as the reported question's third part.

You are given an array of iterators, where iterators[i] lists the elements that iterator i returns, in order. Build a single round-robin iterator over them:

  • The iterators take turns in index order: iterator 0, then 1, then 2, and so on, and after the last one the turns go back to iterator 0.
  • On its turn, an iterator contributes exactly one element, its next one.
  • An iterator with no elements left is skipped, so its turn goes to the next iterator that still has elements. Empty iterators are skipped from the start.

The round-robin iterator supports two operations:

  • "next" returns the next element in round-robin order.
  • "hasNext" returns whether any element remains. It does not consume anything.

Process operations in order and return one string per operation: the returned element as a decimal string for "next", and "true" or "false" for "hasNext".

Function

roundRobinIterator(iterators: int[][], operations: String[]) → String[]

Examples

Example 1

iterators = [[1,2,3],[4],[5,6]]operations = ["next","next","next","next","next","hasNext","next","hasNext"]return = ["1","4","5","2","6","true","3","false"]
  • Round 1 takes one element from each iterator in order: 1, 4, 5.
  • The second iterator is now exhausted and is skipped, so round 2 gives 2 and 6, and round 3 gives 3.
  • Before the last next one element (3) is left, so hasNext is "true"; after it, hasNext is "false".

Example 2

iterators = [[],[7,8],[]]operations = ["hasNext","next","next","hasNext"]return = ["true","7","8","false"]
  • Empty iterators are skipped from the start, so only the second iterator contributes: 7, then 8.

Example 3

iterators = [[]]operations = ["hasNext"]return = ["false"]
  • The only iterator is empty, so there is nothing to return.

Constraints

  • 1 <= iterators.length <= 1000
  • 0 <= iterators[i].length <= 1000
  • The iterators hold at most 1000 elements in total.
  • -1000 <= iterators[i][j] <= 1000
  • 1 <= operations.length <= 2000
  • Each operations[k] is "next" or "hasNext".
  • "next" is only called when an element remains.

More Bridge interview questions

  • Select Object by Key ExtremePHONE SCREEN · Seen Aug 2026
  • Stepped IteratorPHONE SCREEN · Seen Aug 2026

Similar questions at other companies

  • Design Hit CounterNutanix · ONSITE INTERVIEWNutanix interview questions
  • Five-Minute Hit CounterGoogle · ONSITE INTERVIEWGoogle interview questions
  • Ring Buffer OperationsAmazon · ONSITE INTERVIEW
  • Recent Hit CounterAmazon Web Services · ONSITE INTERVIEWAmazon Web Services interview questions
  • Design Hit CounterCharta Health · PHONE SCREENCharta Health interview questions
  • Constant-Time Weighted Pick with an Alias TableEtched · PHONE SCREEN
  • Implement a FIFO QueueByteDance · PHONE SCREENByteDance interview questions
  • Stateful Paginated Fetch NLyft · PHONE SCREENLyft interview questions
  • Music Player Operation SequenceAtlassian · PHONE SCREENAtlassian interview questions
  • Machine Message RouterOpenAI · PHONE SCREENOpenAI interview questions
All Bridge interview questionsSee Bridge hiring insights
Saved
class Solution {
    public String[] roundRobinIterator(int[][] iterators, String[] operations) {
        // Write your code here.
    }
}
Checking account…