As reported: DocuSign Software Engineer loop, Bangalore (2026), round 1 (45 minutes on Zoom + HackerEarth): the standard merge of two sorted arrays — a naive approach first, then the implementation — followed by a follow-up question.
This is LeetCode 88 — Merge Sorted Array.
You are given two integer arrays nums1 and nums2, sorted in non-decreasing order, and two integers m and n: the number of elements in nums1 and nums2. nums1 has length m + n; its first m elements are the real values and the last n are 0 placeholders.
Merge nums2 into nums1 in place so that nums1 becomes one sorted array of length m + n.
Example 1
nums1 = [1,2,3,0,0,0], m = 3, nums2 = [2,5,6], n = 3 -> [1,2,2,3,5,6]
Example 2
nums1 = [1], m = 1, nums2 = [], n = 0 -> [1]
Example 3
nums1 = [0], m = 0, nums2 = [1], n = 1 -> [1]
Constraints: 0 ≤ m, n ≤ 200; 1 ≤ m + n ≤ 200; -10^9 ≤ nums1[i], nums2[j] ≤ 10^9.
Code runner format: four lines — nums1, m, nums2, n (LeetCode's test-case format). Implement merge(nums1, m, nums2, n), which changes nums1; the harness prints nums1.
Follow-ups
- What if the array is big but its elements come from a small group of distinct values?