Question: Merge 2 arrays in 1 array You are given a function mergeArrays which takes in two sorted arrays a and b as parameters. The first

Merge 2 arrays in 1 array
You are given a function mergeArrays which takes in two sorted arrays a and b as parameters. The first array has M elements in it. The second one also has M elements, but it's capacity is 2M. The function mergeArrays takes both the arrays as parameters along with M. Merge the first array into the second array such that the resulting array is sorted. The code to handle input and output in the format required by the test case files is already present in the system. There is no need to edit that part of the program.
Your task is to complete the body of mergeArrays with the signature provided, and to return the correct output.
Constraints
10M1,000
Sample Input:
a={3,5,6,9,12,14,18,20,25,28}
b={30,32,34,36,38,40,42,44,46,48}
Sample Output:
{3,5,6,9,12,14,18,20,25,28,30,32,34,36,38,40,42,44,46,48}
Explanation:
As stated in the question, the second array contains enough space to accommodate the 1st array. Return the merged sorted array.
 Merge 2 arrays in 1 array You are given a function

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!