# Merge Two Sorted Arrays

Moderate
0/80
Average time to solve is 15m
Contributed by

## Problem statement

Ninja has been given two sorted integer arrays/lists â€˜ARR1â€™ and â€˜ARR2â€™ of size â€˜Mâ€™ and â€˜Nâ€™. Ninja has to merge these sorted arrays/lists into â€˜ARR1â€™ as one sorted array. You may have to assume that â€˜ARR1â€™ has a size equal to â€˜Mâ€™ + â€˜Nâ€™ such that â€˜ARR1â€™ has enough space to add all the elements of â€˜ARR2â€™ in â€˜ARR1â€™.

For example:

``````â€˜ARR1â€™ = [3 6 9 0 0]
â€˜ARR2â€™ = [4 10]
After merging the â€˜ARR1â€™ and â€˜ARR2â€™ in â€˜ARR1â€™.
â€˜ARR1â€™ = [3 4 6 9 10]
``````
Detailed explanation ( Input/output format, Notes, Images )
Constraints:
``````1 <= â€˜Tâ€™ <= 100
1 <= â€˜Mâ€™, â€˜Nâ€™ <= 5000
1 <= â€˜ARR1[i], ARR2[i]â€™ <= 100000

Time Limit: 1 second
``````
##### Sample Input 1:
``````2
3 2
1 2 3 0 0
4 5
4 2
1 4 6 10 0 0
2 5
``````

#### Sample Output 1:

``````1 2 3 4 5
1 2 4 5 6 10
``````

#### Explanation for Sample Output 1:

``````For sample test case 1:
In this test case, After merging â€˜ARR2â€™ into â€˜ARR1â€™.
â€˜ARR1â€™ = [1 2 3 4 5]

For sample test case 2:
In this test case, After merging â€˜ARR2â€™ into â€˜ARR1â€™.
â€˜ARR1â€™ = [1 2 4 5 6 10]
``````
##### Sample Input 2:
``````2
2 3
1 10 0 0 0
3 8 11
3 3
3 4 6 0 0 0
1 8 10
``````

#### Sample Output 2:

``````1 3 8 10 11
1 3 4 6 8 10
``````

#### Explanation for Sample Output 2:

``````For sample test case 1:
In this test case, After merging â€˜ARR2â€™ into â€˜ARR1â€™.
â€˜ARR1â€™ = [1 3 8 10 11]

For sample test case 2:
In this test case, After merging â€˜ARR2â€™ into â€˜ARR1â€™.
â€˜ARR1â€™ = [1 3 4 6 8 10]
``````
Console