Zigzag Iterator Over Two Lists
Problem statement
Given two integer arrays first and second, return their values in zigzag order.
Take one value from first, then one from second, and continue alternating. When one array is exhausted, append all remaining values from the other array in their original order.
Function
zigzagIterate(first: int[], second: int[]) → int[]Examples
Example 1
first = [1,2]second = [3,4,5,6]return = [1,3,2,4,5,6]The arrays alternate until first is exhausted, then the remaining values from second follow.
Example 2
first = []second = [7,8]return = [7,8]An empty first array is skipped.
Example 3
first = [1,2,3]second = []return = [1,2,3]An empty second array is skipped.
Constraints
0 <= first.length, second.length <= 100000.first.length + second.length >= 1.- Every value is a signed 32-bit integer.