← Back to Arrays
Question 398
Merge Two Sorted Arrays
Merge Two Sorted Arrays
Two already-sorted arraysa = {1, 3, 5, 7}andb = {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 fromaorb. 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
Sign in to use hintsTopics:
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.