Loading...
Implement an iterator to flatten a 2D vector. Support next() and has_next() operations.
Input: 2D vector as JSON, then operations separated by semicolons. Output results of next() calls.
[[1,2],[3],[4]] next;next;next;has_next;next;has_next
1 2 3 True 4 False
[[1,2],[3],[4]] is initialized for iteration.next() operation is called three times, yielding the values 1, 2, and 3, which are the first elements of each of the first three sub-vectors.has_next() operation checks if there are more elements and returns True because there is still an element 4 left in the vector.next() operation is called again, yielding the value 4, which is the last element in the vector.has_next() operation returns False because there are no more elements left to iterate over in the vector.