Loading...
Loading...
Loading...
Selection sort repeats a round: find the smallest value in the unsorted part (the first one if tied) and swap it with the first place of that part. Print the list after exactly k rounds, or after it is fully sorted if k is larger than needed.
Example 1
Input
29 10 14 37 13 1
Output
10 29 14 37 13
One round moves 10 to the front.
Example 2
Input
29 10 14 37 13 2
Output
10 13 14 37 29
Try the problem first. Open one hint at a time.
Each round has the same two steps: find the smallest index, then swap.
Use a strict < so the first smallest value is chosen.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor