FastPrepStepped Iterator
Problems/Stepped Iterator

Stepped Iterator

Bridge logoBridge● EasyFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The source describes hasNext and next like a Java Iterator, adds a step parameter, and gives the sequence for step two. It asks about running out of items, different steps, bad input, and tests. It does not say which steps are valid or what exactly to return at the end or for bad input. Our version is about 90% the same as the reported question.

Simulate a stepped iterator over the integer array values for the ordered operation sequence operations. Return one string result for every operation, in the same order.

For a positive step, the iterator starts before the first element and its next zero-based index is step - 1. Process each operation as follows:

  • HAS_NEXT returns "true" when the next index is inside values, or "false" otherwise. It never changes the iterator state.
  • NEXT returns the integer at the next index as a decimal string, then advances the next index by step.
  • An exhausted NEXT returns "ERROR_EXHAUSTED" and leaves the state unchanged.
  • An operation other than HAS_NEXT or NEXT returns "ERROR_INVALID_OPERATION" and leaves the state unchanged.

If step is not positive, every operation returns "ERROR_INVALID_STEP" and no iterator state is created.

Function

runSteppedIterator(values: int[], step: int, operations: String[]) → String[]

Examples

Example 1

values = [1,2,3,4,5,6]step = 2operations = ["NEXT","NEXT","NEXT"]return = ["2","4","6"]

The successive next positions are 2, 4, and 6 in one-based order, so the three NEXT operations emit 2, 4, and 6.

Example 2

values = [10,20,30,40,50]step = 3operations = ["HAS_NEXT","NEXT","HAS_NEXT","NEXT","HAS_NEXT"]return = ["true","30","false","ERROR_EXHAUSTED","false"]

The first HAS_NEXT is true and NEXT emits 30. The next stepped position is outside the array, so later checks are false and the exhausted NEXT reports its error without changing state.

Example 3

values = [7,8]step = 1operations = ["UNKNOWN","HAS_NEXT","NEXT"]return = ["ERROR_INVALID_OPERATION","true","7"]

The unknown operation reports an error without moving the iterator. The following HAS_NEXT remains true, and NEXT still emits the first value.

Example 4

values = [7,8]step = 0operations = ["HAS_NEXT","NEXT"]return = ["ERROR_INVALID_STEP","ERROR_INVALID_STEP"]

A non-positive step is invalid from the start, so every operation returns the invalid-step error.

Constraints

  • 0 <= values.length.
  • Values less than or equal to 0 for step follow the invalid-step rule.
  • 0 <= operations.length, and every operation is a non-null string.

More Bridge interview questions

  • Select Object by Key ExtremePHONE SCREEN · Seen Aug 2026
  • Round-Robin Iterator over IteratorsONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Lazy Filter over a GeneratorSquarepoint Capital · PHONE SCREENSquarepoint Capital interview questions
  • Array-Backed Set Without Library CollectionsOde with Anthropic · PHONE SCREEN
  • Customer Bootstrap APIDoorDash · PHONE SCREEN · ONSITE INTERVIEWDoorDash interview questions
  • Constant-Time Weighted Pick with an Alias TableEtched · PHONE SCREEN
  • Billing Log with Undo and RedoReddit · PHONE SCREENReddit interview questions
  • Count Events in Rolling Minute WindowsMeta · PHONE SCREENMeta interview questions
  • Process On-Call Routing OperationsOpenAI · PHONE SCREENOpenAI interview questions
  • Implement a FIFO QueueByteDance · PHONE SCREENByteDance interview questions
  • Stateful Paginated Fetch NLyft · PHONE SCREENLyft interview questions
  • Escape Room LeaderboardPinterest · PHONE SCREEN · ONSITE INTERVIEWPinterest interview questions
All Bridge interview questionsSee Bridge hiring insights
Saved
class Solution {
    public String[] runSteppedIterator(int[] values, int step, String[] operations) {
        // write your code here
    }
}
Checking account…