Baseline Heaps · Learning O(n) · O(1)
A support desk's ticket array is currently organized so the front holds the least urgent ticket (a min arrangement). Management wants the exact same array positions reorganized so the front holds the most urgent one (a max arrangement), in place. Since the input already satisfies the complete-tree shape, a bottom-up pass of downward fixes flips the polarity without touching the array's size.
Input: An integer array arr representing a valid min heap of size n.
Output: Return the array reorganized into a valid max heap.
1 <= n <= 10^5-10^9 <= arr[i] <= 10^9The conversion must happen in placeInput: {"arr":[3,5,6,9,12]}
Output: [12,9,6,3,5]
Sifting down from the last internal node lifts 12 to the root and settles the rest into max order.
Input: {"arr":[1,3,2,7,6,5,4]}
Output: [7,6,5,3,1,2,4]
The Floyd build pass rearranges every subtree bottom-up.