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.
- Use two pointers
iandj. - Compare and print the smaller value, then advance that pointer.
- Once one array is finished, print the remaining items of the other.
01EXAMPLE 1
Input
arr1=[1, 3], arr2=[2, 4]Output
1
2
3
4Explanation: Merged in order.
Constraints
- Do not use .sort() or .concat().
ArraysTwo Pointers
JavaScriptSystem handles I/O — write your function only
Loading...
1 Hidden
Input Arguments
arr1[1,3]
arr2[2,4]
Expected Output
1 2 3 4
Click RUN to test your solution