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.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Maximize the size of array by deleting exactly k sub-arrays to make array prime
- Count number of permutation of an Array having no SubArray of size two or more from original Array
- Reverse an array in groups of given size
- Greatest contiguous sub-array of size K
- Find if there is any subset of size K with 0 sum in an array of -1 and +1
- Find Maximum XOR value of a sub-array of size k
- Generate an array of size N according to the given rules
- Subsequences of size three in an array whose sum is divisible by m
- Find an array of size N having exactly K subarrays with sum S
- Count Inversions of size three in a given array
- Count the Arithmetic sequences in the Array of size at least 3
- Check given array of size n can represent BST of n levels or not
- Generate an array of size K which satisfies the given conditions
- Maximum size of sub-array that satisfies the given condition
- Find an array of size N that satisfies the given conditions
- Find a subarray whose sum is divisible by size of the array
- Reverse an array in groups of given size | Set 2 (Variations of Set 1 )
- Create an array of size N with sum S such that no subarray exists with sum S or S-K
- Check if a key is present in every segment of size k in an array
- Size of the largest divisible subset in an Array