Input: v1 =[1,2], v2 =[3,4,5,6]Output: [1,3,2,4,5,6]Explanation: By calling next repeatedly until hasNext returns false, the order of elements returned by next should be:[1,3,2,4,5,6].
Example 2:
1
2
Input: v1 =[1], v2 =[]Output: [1]
Example 3:
1
2
Input: v1 =[], v2 =[1]Output: [1]
Clarification for the follow up question
The “Zigzag” order is not clearly defined and is ambiguous for k > 2 cases. If “Zigzag” does not look right to you, replace “Zigzag” with “Cyclic”. For example:
Initialization: Initialize the constructor with the two vectors and set up necessary pointers to track the current position in both vectors.
hasNext Method: This method checks if there are any remaining elements in either of the vectors.
next Method: This method returns the current element and advances the pointer to the next element. The iteration should alternate between the two vectors.