#C14041. Merge Sorted Arrays
Merge Sorted Arrays
Merge Sorted Arrays
You are given two sorted arrays. Your task is to merge these two arrays into a single sorted array without using any built-in sort functions. Use the two‐pointer approach to achieve this.
Formally, given two arrays \(A\) and \(B\) of sizes \(n\) and \(m\) respectively, you need to produce a sorted array \(C\) containing all elements from \(A\) and \(B\). The merging process should have a linear time complexity \(O(n+m)\).
inputFormat
The first line contains two integers \(n\) and \(m\), representing the sizes of the two arrays. The second line contains \(n\) space-separated integers representing the first sorted array. The third line contains \(m\) space-separated integers representing the second sorted array. If an array is empty, its corresponding line will be empty.
outputFormat
Output the merged sorted array as a sequence of space-separated integers in one line.
## sample3 3
1 3 5
2 4 6
1 2 3 4 5 6