Loading...
Loading...
Loading...
A trainee sorts a list of ticket numbers with bubble sort: repeatedly swap neighbours that are out of order, until no swap is needed. Print how many swaps are made in total.
Example 1
Input
3 1 2
Output
2
Example 2
Input
1 2 3
Output
0
Try the problem first. Open one hint at a time.
Simulate it: two loops with a swap counter.
Equal neighbours are not swapped.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor