Problem
Combine two sorted integer arrays into one sorted sequence without using a built-in sorting routine. This practice version allows an output array.
Worked examples
Input: a = [1,4], b = [2,3]
Output: [1,2,3,4]
Take the smaller current value, advancing only that input pointer.
Hints
Hint 1
Exploit the fact that both arrays are already sorted.
Solution approach
- Maintain one pointer per array and append the smaller current value.
- When one input is exhausted, append the rest of the other.
- Clarify whether the interviewer requires in-place merging; that is a different space constraint.
Complexity
O(n + m) time, O(n + m) output space.
Report & practice notes
Restated practice version with original examples and explanation. The source is a candidate account, not an official question paper; assessment details can vary. Difficulty is our editorial estimate.
Read the candidate’s source report ↗