Quant Memo
Coding/●●●●●

Merge two sorted arrays in place

You are given nums1, an array of length m + n whose first m slots hold a sorted sequence and whose last n slots are placeholders, and nums2, a sorted array of length n. Merge nums2 into nums1 so nums1 ends up fully sorted, doing it in place (no second output array).

nums1 = [1, 2, 3, 0, 0, 0], m = 3
nums2 = [2, 5, 6],          n = 3
-> [1, 2, 2, 3, 5, 6]

Target O(m+n)O(m + n) time and O(1)O(1) extra space.

Your answer

This one is open-ended. Work it through, then check your reasoning against the full solution.

More Coding questions