Problem title
Avg time to solve

Sorting Of A Rotated Sorted Array
10 mins
Sum of Bit Difference Among all Pairs
15 mins
Word Boggle
Social Networking Graph
15 mins
Minimum Cost to Make at Least One Valid Path in a Grid
20 mins
Allocate Books
Generate all binary strings from pattern
10 mins
Pair Difference K
15 mins
Best Time to Buy and Sell Stock III
10 mins
Rotated Array
10 mins

Ninja And The List

Difficulty: MEDIUM
Contributed By
Avg. time to solve
24 min
Success Rate

Problem Statement

Ninja has given a nested list of integers nestedList of size 'N'. Each element is either an integer or a list whose elements may also be integers or other lists.

Ninjas have asked to implement the following methods of the NestedIterator class.

NestedIterator(vector<NestedInteger> nestedList) Initializes the 
iterator with the nested list nestedList.
int next() Returns the next integer in the nested list.
bool hasNext() Returns true if there are still some integers in the nested list and false otherwise.

Your task is to help the ninja to implement the above methods.

Your code will be tested with the following pseudocode:

initialize iterator with nestedList
  answer = []
  while iterator.hasNext()
    append to the end of answer
    return answer

You will get the correct answer verdict if the answer matches the expected flattened list.

Input List: [[1, 1], 2, [1, 1]]
Output List: [1, 1, 2, 1, 1]
Input Format :
The first line contains 'T', the number of test cases.
For each test case, there will be only one line in the input containing integers and some nested lists.
Output format :
Print the second line containing the flattered nested list.
Note :
You don't need to print anything. It has already been taken care of. Just implement the given class.
Constraints :
1 <= 'T' <= 10
1 <= 'N' <= 10^5
0 <= Values of integers in the nested list <= 10^5
Time Limit: 1sec
Reset Code
Full screen