@csehaosh I 99% agree.1% disagreement is that the poster's solution works fine when calling hasNext() multiple times. But its drawback is inefficiency. e.g. There are 1000000000 Integers in nestedList and the user only calls next() once. -> You have to put 1000000000 Integers into stack, but the user only takes the 1st one. Instead, we should push to stack "lazy". Many following solutions are "generically" wrong (although work in this problem). Because they change internal status in hasNext(). Instead, we should cache "hasNext flag" to make sure even calling hasNext() multiple times before next() will return the same result.
Flatten Nested List Iterator