#C9361. Merging Two Arrays Alternately
Merging Two Arrays Alternately
Merging Two Arrays Alternately
In this problem, you are given two arrays. Your task is to merge these arrays by alternatingly taking elements from each array. If one array is longer, append the remaining elements at the end of the merged array.
Formally, let (A = [a_0,a_1,\dots,a_{n-1}]) and (B = [b_0,b_1,\dots,b_{m-1}]). The merged array (M) is defined as:
[
M = \begin{cases}
[a_0, b_0, a_1, b_1, \dots, a_{n-1}, b_{n-1}, b_n, \dots, b_{m-1}] & \text{if } n \le m,\
[a_0, b_0, a_1, b_1, \dots, b_{m-1}, a_{m}, \dots, a_{n-1}] & \text{if } m < n.
\end{cases}
]
inputFormat
The input consists of two lines. The first line contains the elements of the first array separated by spaces (this line may be empty, indicating an empty array). The second line contains the elements of the second array separated by spaces (which may also be empty).
outputFormat
Output a single line containing the elements of the merged array separated by a single space. If the merged array is empty, output an empty line.## sample
1 2 3
4 5 6
1 4 2 5 3 6