Loading...
Loading...
Loading...
Two warehouses each send a price list that is already sorted from low to high. Merge them into one sorted list by repeatedly taking the smaller of the two front prices. Do not call Collections.sort.
Example
Input
3 10 40 90 4 5 40 60 100
Output
5 10 40 40 60 90 100
On a tie either 40 can go first; the output is the same.
Try the problem first. Open one hint at a time.
Keep two indexes, i for the first list and j for the second, and compare a.get(i) with b.get(j).
When one list is used up, copy what is left of the other.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor