There are two sorted arrays. First one is of size m+n containing only m elements. Another one is of size n and contains n elements. Merge these two arrays into the first array of size m+n such that the output is sorted.
Input: array with m+n elements (mPlusN).
NA => Value is not filled/available in array mPlusN. There should be n such array blocks.
Input: array with n elements (N).
Output: N merged into mPlusN (Modified mPlusN)
Let first array be mPlusN and other array be N 1) Move m elements of mPlusN to end. 2) Start from nth element of mPlusN and 0th element of N and merge them into mPlusN.
Below is the implementation of the above algorithm :
2 5 7 8 9 13 15 20 25
Time Complexity: O(m+n)
Please write comment if you find any bug in the above program or a better way to solve the same problem.
- Count Inversions of size three in a given array
- Find if there is any subset of size K with 0 sum in an array of -1 and +1
- Reverse an array in groups of given size
- Subsequences of size three in an array whose sum is divisible by m
- Find Maximum XOR value of a sub-array of size k
- Check given array of size n can represent BST of n levels or not
- Smallest subarray whose sum is multiple of array size
- Check if a key is present in every segment of size k in an array
- Reverse an array in groups of given size | Set 2 (Variations of Set 1 )
- Find the only repeating element in a sorted array of size n
- Maximum product of a triplet (subsequnece of size 3) in array
- Maximise the size of consecutive element subsets in an array
- Maximum product quadruple (sub-sequence of size 4) in array
- Minimum array size after repeated replacement of even sum pair with sum
- Given an array of of size n and a number k, find all elements that appear more than n/k times