FastPrepFlatten Nested List Iterator
Problems/Flatten Nested List Iterator

Flatten Nested List Iterator

NVIDIA logoNVIDIA● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an NVIDIA phone screen for a full-time role. The report names the standard nested-list iterator without a full statement. We kept the usual next and hasNext behavior. We chose a finite sequence of calls and more limits on size.

Our version is about 85% the same as the reported question.

Build an iterator over a nested list of integers. Each item in the list is either a signed integer or another list. The iterator hands out the integers one at a time, in the order you meet them when you read the list from left to right and step into each inner list as you reach it. An empty list adds no values.

The string nestedList holds that list written as valid JSON. Create one iterator, then run the calls in operations in order:

  • HAS_NEXT tells you whether an integer is still left. It does not use up the integer, so calling it again sees the same next value.
  • NEXT returns the next integer and moves past exactly that one. It can be called without a HAS_NEXT check first. An integer is always left whenever NEXT is called.

Return one string for each operation: "true" or "false" for HAS_NEXT, and the integer itself for NEXT, written as a plain decimal number with no plus sign or extra leading zeros. Repeated integers, negative values and zero are all returned like any other value.

The calls may stop before every integer has been read. Return results only for the calls that were made. The nested list never changes, and there is no remove call.

Function

runNestedIterator(nestedList: String, operations: String[]) → String[]

Examples

Example 1

nestedList = "[[1,1],2,[1,1]]"operations = ["HAS_NEXT","HAS_NEXT","NEXT","NEXT","HAS_NEXT","NEXT","NEXT","NEXT","HAS_NEXT"]return = ["true","true","1","1","true","2","1","1","false"]

Both HAS_NEXT calls at the start see the same first integer, so neither one uses it up. The five NEXT calls then return 1, 1, 2, 1, 1, in list order. By the last HAS_NEXT call every integer has been read, so it returns "false".

Example 2

nestedList = "[1,[4,[6]]]"operations = ["NEXT","HAS_NEXT","NEXT","HAS_NEXT","NEXT","HAS_NEXT"]return = ["1","true","4","true","6","false"]

The calls read the integers from left to right, stepping into each inner list as they reach it: 1, then 4, then 6. Nothing is left after that, so the last HAS_NEXT returns "false".

Example 3

nestedList = "[[],[7,[]],[]]"operations = ["HAS_NEXT","NEXT","HAS_NEXT","HAS_NEXT"]return = ["true","7","false","false"]

The empty lists hold no integers, so the only value is 7. After NEXT returns it, both later HAS_NEXT calls return "false".

Constraints

  • nestedList is valid JSON that holds only arrays and integers. The outer value is an array with 1 to 500 items.
  • Every integer is in the range -10^6 <= value <= 10^6. Empty inner arrays and JSON whitespace are allowed.
  • There are at most 2000 integers and arrays in total, counting the outer array. Arrays are nested at most 30 levels deep, and nestedList has at most 20000 characters.
  • 1 <= operations.length <= 1000. Each operation is HAS_NEXT or NEXT, and an integer is always left whenever NEXT is called.

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

  • N-ary Index-Path Encoder and DecoderBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Billing Log with Undo and RedoReddit · PHONE SCREENReddit interview questions
  • KV Store with Nested TransactionsApplied Intuition · PHONE SCREEN · ONSITE INTERVIEWApplied Intuition interview questions
  • Validate a BST with a Custom ComparisonApple · PHONE SCREENApple interview questions
  • Multiline Text Editor with Cursor MovementDatologyAI · PHONE SCREEN
  • Layer History with Batch Undo and RedoFigma · OA · PHONE SCREENFigma interview questions
  • Stack with Constant-Time Middle QueriesAmazon · PHONE SCREEN
  • In-Memory Database with Transactions and SavepointsNextdoor · PHONE SCREENNextdoor interview questions
  • Throne Inheritance Without an Initial KingSnowflake · PHONE SCREENSnowflake interview questions
  • Find File Paths in a Directory TreeUber · PHONE SCREENUber interview questions

NVIDIA interview experiences

  • NVIDIA Full-Time SWE Onsite Scheduling: 1 Experience
  • NVIDIA OA: What It Tests (2026)
  • NVIDIA DevOps, QA and Infra Intern Interviews: 12 Experiences
  • NVIDIA Ignite Internship OA Experience
  • NVIDIA Software Intern Interview Questions: 9 Experiences
  • NVIDIA Ignite SWE Intern OA Questions: 6 Experiences
All NVIDIA interview questionsSee NVIDIA hiring insights
Saved
class Solution {
    public String[] runNestedIterator(String nestedList, String[] operations) {
        // Build one nested-list iterator and return each requested operation result.
    }

}
Checking account…