Merge two sorted arrays in-place
Company: Amazon
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: hard
Interview Round: Technical Screen
Quick Answer: This question evaluates array-manipulation and in-place algorithm skills, including understanding of sorted-data merging, index/pointer management, and analysis of time and space complexity within the Coding & Algorithms domain.
Constraints
- The last n positions of arr1 are free capacity
Examples
Input: ([1, 2, 3, None, None, None], 3, [2, 5, 6], 3)
Expected Output: [1, 2, 2, 3, 5, 6]
Explanation: Standard merge from the back.
Input: ([0], 0, [1], 1)
Expected Output: [1]
Explanation: arr1 has no valid initial values.
Input: ([2, None], 1, [1], 1)
Expected Output: [1, 2]
Explanation: arr2 value belongs before arr1 value.
Input: ([1, 2], 2, [], 0)
Expected Output: [1, 2]
Explanation: arr2 empty.
Hints
- Fill from the end so unmerged arr1 values are not overwritten.