#K82477. Merge Alternate Arrays
Merge Alternate Arrays
Merge Alternate Arrays
You are given two arrays A and B. Your task is to merge these two arrays alternately. Specifically, if we denote the sizes as \( n = |A| \) and \( m = |B| \), then the merged array is constructed as follows:
Take the first element of A, then the first element of B, then the second element of A, then the second element of B, and so on for \( \min(n, m) \) elements. If one of the arrays is exhausted before the other, append the remaining elements of the other array to the end.
For example, if A = [1, 3, 5] and B = [2, 4, 6], then the merged array is [1, 2, 3, 4, 5, 6].
inputFormat
The input consists of two lines:
- The first line contains the elements of array A separated by spaces. If the line is empty, then A is an empty array.
- The second line contains the elements of array B separated by spaces. If the line is empty, then B is an empty array.
All elements are integers.
outputFormat
Output the merged array on a single line. The elements of the merged array should be printed in order and separated by a single space.
## sample1 3 5
2 4 6
1 2 3 4 5 6