Loading...
Loading...
Two sections of a college class took the same mock test. Each section sent the placement cell its list of ranks, already sorted from best (smallest) to worst. Print one combined list of all the ranks in sorted order. If a rank appears more than once, keep every copy.
Example
Input
4 3 2 5 9 14 1 5 20
Output
1 2 5 5 9 14 20
Take the smaller front value each time. Rank 5 is in both lists, so it appears twice.
Try the problem first. Open one hint at a time.
Both lists are already sorted, so the smallest rank left is always at the front of one of them.
Keep one index for each list. Compare the two front values and print the smaller one.
Move forward only the index whose value you just printed.
When one list runs out, print everything that is left in the other list.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor