Solution: Zigzag Iterator
C# solution for the Zigzag Iterator problem using the K-way Merge pattern.
We'll cover the following...
We'll cover the following...
Statement
Design an iterator class ZigzagIterator that takes two integer arrays v1 and v2 and iterates through their elements by alternating between the arrays.
The iterator must support the following methods:
next()returns the next integer in the alternating traversal.hasNext()returnstrueif there is at least one remaining element to return, otherwise returnsfalse.
When one of the arrays runs out of elements, the iterator should continue returning the remaining elements from the other array in order.
Note: For the follow up, if more than two arrays are provided, interpret the order as cyclic across the arrays, skipping any array that has no remaining elements.
Constraints:
...