Heapsort builds a max-heap and then repeats one move: swap the root, which holds the largest remaining value, with the last item of the heap, shrink the heap by one so that item is now part of the finished tail, and sift the new root down.
Write heapsort_rounds(nums, rounds) returning the array after Floyd's build followed by exactly rounds of that move, stopping early if the heap shrinks to one item.
Examples
Input: nums = [4, 10, 3, 5, 1], rounds = 1
Output: [5, 4, 3, 1, 10]
Explanation: the heap is [10, 5, 3, 4, 1]; 10 goes to the end and the rest is repaired.
Input: nums = [1, 2, 3], rounds = 0
Output: [3, 2, 1]
Explanation: with no rounds the answer is just the heap Floyd's build produces.
Constraints
0 <= len(nums) <= 10**5,0 <= rounds <= 10**5, values are integers- No extra array: everything happens inside the one list.
Goals
- Sort with no memory beyond the array itself
- Swap the maximum into the shrinking tail and repair what is left
- Watch the sorted part grow from the right