Skip to content

URK21CS2020AKASHNAIR/exercise-9-c-merge-sorted-arrays-URK21CS2052-SAMSON

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Problem Statement

You are given two integer arrays nums1 and nums2, sorted in ascending order, and two integers m and n, representing the number of elements to be merged in nums1 and nums2 respectively.

Merge nums1 and nums2 into a single array sorted in ascending order.

The final sorted array should not be returned by the function, but instead be stored inside the array, nums1.
To accommodate this, nums1 has a length of m + n, where the first m elements denote the elements that should be merged, and the last n elements should be ignored.

Example

Input: nums1 = [1,2,3,4,5,6], m = 3, nums2 = [2,5,6], n = 3
Output: [1,2,2,3,5,6]
Explanation: The arrays we are merging are [1,2,3] and [2,5,6].
The result of the merge is [1,2,2,3,5,6] with the underlined elements coming from nums1.

Constraints

nums1.length == m + n
nums2.length >= n
0 <= m, n <= 200
1 <= m + n <= 200
-109 <= nums1[i], nums2[j] <= 109

Sample Input - 1

1, 2, 3, 4, 5, 6
7, 8, 9
4
2

First line represents nums1.
Second line represents nums2.
Third line shows m, which represents first four elements from nums1 will be processed.
Fourth line shows n, which represents first two elements from nums2 will be processed.

Sample Output - 1

[1, 2, 3, 4, 7, 8]

Sample Input - 2

7, 8, 9, 10, 11, 12
1, 2, 3, 4
4
2

Sample Output - 2

[1, 2, 7, 8, 9, 10]

About

exercise-9-c-merge-sorted-arrays-URK21CS2052-SAMSON created by GitHub Classroom

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%