281. Zigzag Iterator
Problem
Design an iterator that iterates over two vectors in zigzag order (alternating between them).
Given two vectors (or lists) v1 and v2, design an iterator that returns elements in zigzag order: one element from v1, one from v2, one from v1, one from v2, and so on.
If one vector runs out, continue with the remaining elements from the other vector.
Examples
Input: [["ZigzagIterator","next","next","next","next","next","next"],[[[1,2],[3,4,5,6]],[],[],[],[],[],[]]]
Output: [null,1,3,2,4,5,6]
Input: [["ZigzagIterator","next","next","next","next","next","next"],[[[1,2],[3,4,5,6]],[],[],[],[],[],[]]]
Output: [null,1,3,2,4,5,6]
Hints
Use a queue to manage iterators or indices.
Alternate between lists each time next() is called.
When one list is exhausted, continue with the remaining list.
Related Problems
281. Zigzag Iterator
Design an iterator that iterates over two vectors in zigzag order (alternating between them).