Interleave Arrays
EasyData EngineeringArray
Description
Given two arrays, interleave them by alternating elements: first of a, first of b, second of a, second of b, and so on. When one array is longer, append its remaining elements at the end.
Examples
Input:
[1,2,3], [4,5,6]Output:
[1,4,2,5,3,6]Explanation:
Elements are taken in turn from the two arrays, and once the shorter one runs out the remainder of the longer is appended.
Input:
[1,2], [3,4,5,6]Output:
[1,3,2,4,5,6]Explanation:
Elements are taken in turn from the two arrays, and once the shorter one runs out the remainder of the longer is appended.
Input:
[1], [2]Output:
[1,2]Explanation:
Elements are taken in turn from the two arrays, and once the shorter one runs out the remainder of the longer is appended.
Constraints
- •
0 ≤ each length ≤ 10⁴