Merge Sorted Array Problem
Merge Sorted Array Problem — ExecCode Easy DSA Practice
Solve the Merge Sorted Array problem on ExecCode. Free online easy DSA practice in Two Pointers. Write and run code in Java, C++, Python — no signup required to run.
Problem description
Merge nums2 into nums1 in place. Because nums1 has empty space at the end, compare from the back and write the larger current value into the last open slot.
Examples
Input nums1 = [1,2,3,0,0,0], m = 3, nums2 = [2,5,6], n = 3; Output [1,2,2,3,5,6]. Input nums1 = [4,5,6,0,0,0], m = 3, nums2 = [1,2,3], n = 3; Output [1,2,3,4,5,6]
Constraints
nums1.length == m + n nums2.length == n 0 ≤ m, n ≤ 200 1 ≤ m + n ≤ 200
Practice Merge Sorted Array free on ExecCode. Browse DSA problems, topic map, and placement guides.