Loading...
Loading...
Loading...
A bus route is stored as an array of stop numbers. For the return trip the conductor wants the first and last stops exchanged, and everything else left as it is. Swap them and print the route.
Example
Input
5 101 205 310 412 520
Output
520 205 310 412 101
Only 101 and 520 change places.
Try the problem first. Open one hint at a time.
The last element is at index n - 1, not n.
Swap with a temporary variable: save one value, overwrite it, then put the saved value in the other place.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor