You are given two sorted arrays, a[] and b[], both arranged in non-decreasing order. The task is to merge these arrays into a single sorted array without using extra space. Modify a so that it contains the first n elements and modify b so that it contains the last m elements.
Example 1
Input: a[] = [2, 4, 7, 10], b[] = [2, 3]
Output: 2 2 3 4 7 10
Explanation: After merging the two non-decreasing arrays, we get, 2 2 3 4 7 10
Example 2
Input: a[] = [1, 5, 9, 10, 15, 20], b[] = [2, 3, 8, 13]
Output: 1 2 3 5 8 9 10 13 15 20
Explanation: After merging two sorted arrays we get 5 10 12 18 20.
Approach, complexity and clean code in every language. Sign in to unlock the editorial.
Your submissions, results and runtime history live here. Sign in to start your streak.
2 4 7 10 2 3
2 2 3 4 7 10
1 5 9 10 15 20 2 3 8 13
1 2 3 5 8 9 10 13 15 20
0 1 2 3
0 1 2 3
1 2
1 2
1 3 5 2
1 2 3 5