The Merge Foundry

MediumAcc. 92.1%
+30 XP 12

Convergent Sorting

When two arrays are already sorted, you can merge them by picking the smallest element from the front of either array.

The Assignment

Your function receives arr1 and arr2.

  1. Use two pointers i and j.
  2. Compare and print the smaller value, then advance that pointer.
  3. Once one array is finished, print the remaining items of the other.

01EXAMPLE 1

Inputarr1=[1, 3], arr2=[2, 4]
Output1 2 3 4

Explanation: Merged in order.

Constraints

  • Do not use .sort() or .concat().
ArraysTwo Pointers
JavaScript
Loading...
1 Hidden

Input Arguments

arr1[1,3]
arr2[2,4]

Expected Output

1
2
3
4

Click RUN to test your solution