Step 1/0
Custom array:
Complexity
Best:O(n log n)
Average:O(n log n)
Worst:O(n log n)
Space:O(1)
Description
Builds a max-heap from the array, then repeatedly extracts the maximum element and places it at the end, rebuilding the heap each time.
When to use
Guaranteed O(n log n) worst case with O(1) space. Use when worst-case performance is critical and space is constrained.