Loading...
Loading...
Loading...
Write the sort yourself with a min-heap: build the heap by hand, then take the smallest item out until it is empty. Print the numbers in ascending order, separated by spaces.
Example 1
Input
6 40 10 30 20 50 10
Output
10 10 20 30 40 50
Equal values stay in the output.
Example 2
Input
1 5
Output
5
Try the problem first. Open one hint at a time.
Write sift_down, then call it on every parent from the last one to index 0.
Pop by swapping the root with the last item, shrinking the heap and sifting the new root down.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor