Description

Given two arrays, design an iterator that returns elements in zigzag order (alternating between arrays).

Examples

Input:v1 = [1,2], v2 = [3,4,5,6]
Output:[1,3,2,4,5,6]
Explanation:

Zigzag: 1,3,2,4,5,6.

Input:v1 = [1], v2 = [1]
Output:[1]
Explanation:

Edge case with a single-element array.

Input:v1 = [7,9,11], v2 = []
Output:[7,9,11]
Explanation:

When one array is empty, the iterator should return all elements from the non-empty array in order.

Constraints

  • 0 ≤ v1.length, v2.length ≤ 1000

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!