Solution: Flatten Nested List Iterator
Let's solve the Flatten Nested List Iterator problem using the Stacks pattern.
We'll cover the following...
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 and .
- The nested list consists of integers between .
Solution
We’ll use a stack to solve this problem. The stack will be used to store the integer and list of integers on ...
Access this course and 1400+ top-rated courses and projects.