The idea behind the classic

a

Implement the

two**sorted** arrays and returns a third **sorted** array that contains elements of both the input arrays.

You can assume

that the input arrays will always be sorted in ascending order and can have different sizes.

Examples:

`Mergesort`

algorithm is to divide an array in half, sort each half, and then usea

`merge()`

method to merge the two halves into a single sorted array. Implement the

`merge()`

method that takes in two

You can assume

that the input arrays will always be sorted in ascending order and can have different sizes.

Examples:

`merge({2,5,7,8,9},{9}) -> {2,5,7,8,9,9}`

`merge()({7,8},{1,2}) -> {1,2,7,8}`

`merge()({2},{}) -> {2}`

` {} -> [Empty] Array `

Need a **hand?** Try out these hints, one at a time.

Assuming that the two input arrays are already sorted, iterate over the elements in both the arrays and insert them into the third array in ascending order. Keep in mind that the size of the third array will be equal to the **sum** of the sizes of the input arrays.

Merging two sorted arrays

`A`

and `B`

creates a third array `C`

that contains all theelements of A and B, arranged in ascending order. To successfully implement this algorithm : 1. Create a third return

array which has a size equal to the sum of the sizes of the input arrays. 2. You could use three while loops, since the lengths of the two

arrays may not be the same.

3. Traverse through both the input arrays and pick the elements in increasing order and add them to the third sorted array.

4. Since the array sizes may not be the same, use the other two loops to account for any remaining elements in the input arrays.

public static int[] merge(int[] arrLeft, int[] arrRight){ }

**C**

**Java**

**Python**