#K64442. Merge Sorted Arrays
Merge Sorted Arrays
Merge Sorted Arrays
You are given two sorted arrays A
and B
of integers. Your task is to merge these two arrays into a single sorted array. The merged array should be printed as a space-separated string of integers.
The expected time complexity is \(O(n+m)\), where \(n\) and \(m\) are the lengths of the two arrays. Make sure to use an efficient merge technique similar to the one used in merge sort.
inputFormat
The input consists of two lines. The first line contains the elements of the first sorted array A
, and the second line contains the elements of the second sorted array B
. All numbers are space-separated.
outputFormat
Output a single line containing the merged sorted array, with each element separated by a single space.
## sample1 3 5 7
2 4 6 8
1 2 3 4 5 6 7 8