Implement an Iterator Next Method
Updated
Problem statement
Implement an iterator over the supplied integer sequence. The iterator stores its current position. Every call to its next method returns the next value in the original order and advances by one. Once no values remain, it is exhausted and every later next call must continue to signal exhaustion.
For this exercise, initialize one iterator from values and make exactly nextCalls calls to it. Return one string per call: the yielded integer in decimal form, or STOP when that call finds the iterator exhausted. In Python, the iterator method should use the standard StopIteration exception, which the judge converts to STOP; other languages should expose the same observable sequence.
Keep repeated values as separate iterator items. The input sequence is not modified.
Function
iterateNextCalls(values: int[], nextCalls: int) → String[]Examples
Example 1
values = [4,-2,4]nextCalls = 5return = ["4","-2","4","STOP","STOP"]The first three calls consume the three values. Both later calls observe the same exhausted state.
Example 2
values = []nextCalls = 2return = ["STOP","STOP"]An empty sequence is exhausted before the first call and remains exhausted.
Example 3
values = [0,9]nextCalls = 1return = ["0"]The single call consumes only the first value; there is no request to exhaust the iterator.
Constraints
0 <= values.length <= 100000-10^9 <= values[i] <= 10^90 <= nextCalls <= 100000
More NVIDIA Phone Screen questions
- Network Layer Execution OrderPHONE SCREEN · Seen Nov 2026
- Paged KV Cache AccessPHONE SCREEN · Seen Nov 2026
- Sliding Window Attention over a KV CachePHONE SCREEN · Seen Nov 2026
- Summarize Server Healthcheck LogsPHONE SCREEN · Seen Oct 2026
- Hash Partition OffsetsPHONE SCREEN · Seen Oct 2026
- Filter Paginated Medical RecordsPHONE SCREEN · Seen Oct 2026
- Least Frequently Used CachePHONE SCREEN · Seen Oct 2026
- Parallel String Counts with a Custom Hash TablePHONE SCREEN · Seen Oct 2026
- Simulate a Reference-Counted Smart PointerPHONE SCREEN · Seen Aug 2026
- Streaming Top-K Frequent ElementsPHONE SCREEN · Seen Aug 2026
Similar questions at other companies
- Logger Rate LimiterGoogle · PHONE SCREENGoogle interview questions
- Lazy Filter over a GeneratorSquarepoint Capital · PHONE SCREENSquarepoint Capital interview questions
- Track New Values in Sorted OrderBloomberg LP · PHONE SCREENBloomberg LP interview questions
- Array-Backed Set Without Library CollectionsOde with Anthropic · PHONE SCREEN
- Stepped IteratorBridge · PHONE SCREENBridge interview questions
- Implement a VectorCitadel · PHONE SCREENCitadel interview questions
- Customer Bootstrap APIDoorDash · PHONE SCREEN · ONSITE INTERVIEWDoorDash interview questions
- Design Hit CounterCharta Health · PHONE SCREENCharta Health interview questions
- Constant-Time Weighted Pick with an Alias TableEtched · PHONE SCREEN
- Billing Log with Undo and RedoReddit · PHONE SCREENReddit interview questions