Practice Flatten Nested List Iterator
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
Implement NestedIterator(nestedList) for a list whose elements are integers or recursively nested lists. next() returns the next integer in left-to-right depth-first order. hasNext() returns whether an unconsumed integer remains. Repeatedly calling next while hasNext is true must produce the same sequence as fully flattening the input; empty nested lists contribute no values.
Source: Flatten Nested List Iterator on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
nestedList = [[1,1],2,[1,1]]
[1,1,2,1,1]
# Example 2
nestedList = [1,[4,[6]]]
[1,4,6]
Constraints
Related LeetCode Problems
Practice more problems similar to Flatten Nested List Iterator.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.