Merge Sorted Array (LeetCode 88): Interview Notes

Nums1 has length m+n with trailing space; merge nums2 (length n) into nums1 in sorted order in-place.

Fill from the back: compare the largest remaining of each array and write at the end pointer.

Time O(m+n), space O(1). Filling forward would need O(m) extra space.

When you want live practice with follow-ups, try the Linkjob AI app.

Disclosure: I work on Linkjob AI.