Tap here to switch tabs
Problem
Ask
Submissions

Problem: Flatten Nested List Iterator

med
30 min
Understand how to create an iterator that flattens nested lists of integers. Explore stack usage to traverse varying nested structures, and develop the hasNext and next functions. This lesson helps improve skills in handling complex data and iterator design, essential for coding interviews.

Statement

You’re given a nested list of integers. Each element is either an integer or a list whose elements may also be integers or other integer lists. Your task is to implement an iterator to flatten the nested list.

You will have to implement the Nested Iterator class. This class has the following functions:

  • Constructor: This initializes the iterator with the nested list.
  • Next (): This returns the next integer in the nested list.
  • Has Next (): This returns TRUE if there are still some integers in the nested list. Otherwise, it returns FALSE.

Constraints

  • The nested list length is between 11 and 200200.
  • The nested list consists of integers between [1,104][1, 10^4].
Tap here to switch tabs
Problem
Ask
Submissions

Problem: Flatten Nested List Iterator

med
30 min
Understand how to create an iterator that flattens nested lists of integers. Explore stack usage to traverse varying nested structures, and develop the hasNext and next functions. This lesson helps improve skills in handling complex data and iterator design, essential for coding interviews.

Statement

You’re given a nested list of integers. Each element is either an integer or a list whose elements may also be integers or other integer lists. Your task is to implement an iterator to flatten the nested list.

You will have to implement the Nested Iterator class. This class has the following functions:

  • Constructor: This initializes the iterator with the nested list.
  • Next (): This returns the next integer in the nested list.
  • Has Next (): This returns TRUE if there are still some integers in the nested list. Otherwise, it returns FALSE.

Constraints

  • The nested list length is between 11 and 200200.
  • The nested list consists of integers between [1,104][1, 10^4].