CJCoding With Joseph
15free / daySign inCreate account

Merge Two Sorted Arrays

Two already-sorted arrays a = {1, 3, 5, 7} and b = {2, 4, 6, 8} are given. Merge them into one sorted array and print it on a single line separated by single spaces (see Expected Output).

Use the two-pointer merge technique: repeatedly take the smaller front element from a or b. Do not just sort a concatenation.

Expected Output:

1 2 3 4 5 6 7 8

= newline. The output ends with a newline — print one after the last line.

Hints4 available
Topics:
Arrays
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (sysout, psvm, fori)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.