Array ( [0] => [1] => questions [2] => Strings [3] => Merge-arrays- )
Given two array of integers, first array contains the m elements and second array contains the n elements. merge an array of size n into another array of size m+n.
First line contains the size of the first array. Next line contains the m integers separated by the spaces. Next line contains the size of the second array. Next line contains the n integers separated by the spaces.
merge an array of size n into another array of size m+n.
5 1 2 3 4 5 6 9 5 7 8 3 1
1 2 3 4 5 9 5 7 8 3 1
3 4 8 7 5 5 6 7 8 9
4 8 7 5 6 7 8 9
7 1 1 1 1 1 1 1 3 8 9 7
1 1 1 1 1 1 1 8 6 7
Login to see Discussion
Approach1:
Step-i) Initialize a new array with size of sum of a and b.
Step-ii) Iterate a for loop and assign values into c from a directly.
Step-iii) Again iterate other for loop for b and assign values into c from starting.
Step-iv) Return the array.
Time Complexity: O(n)
Space Complexity: O(n)
Note :
Let us know if you can come up with a better approach, mail us at support@theinquisitive.in Your approach will be reviewed and posted with credits to you.
Login to see Solution