Loading...
Loading...
Loading...
A queue starts empty. Values are pushed into a min-heap one at a time, in the order given, and each new value moves up while it is smaller than its parent. Print the heap as a list after all pushes.
Example 1
Input
5 7 3 9 1 5
Output
1 3 9 7 5
1 climbs to the top, 5 stays near the bottom.
Example 2
Input
4 1 2 3 4
Output
1 2 3 4
Try the problem first. Open one hint at a time.
Python's heapq.heappush follows the sift-up rule exactly.
Push in the given order and print the list as it is.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor