Loading...
Loading...
Loading...
Order amounts arrive in the order the orders were placed. Print the three largest amounts from the largest down (fewer if there are fewer than three orders). Then print the first order's amount, to show that the original list was not changed. Sort a copy of the list.
Top: <amounts separated by spaces> and then First order: <amount>.Example
Input
6 450 1200 90 3000 799 1200
Output
Top: 3000 1200 1200 First order: 450
Two orders of 1200 both count.
Try the problem first. Open one hint at a time.
Make the copy with new ArrayList<>(orders), sort the copy with Collections.sort, then Collections.reverse it.
Loop Math.min(3, copy.size()) times.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor