AlgoFrames

Spot the bug: the heap that never shrinks

Standard · Find the bug · about 8 min

This heap sort returns a wrong order for most inputs with three or more values. Click the line with the bug, then fix it.

Example 1

Input:

[[9,7,8,4,5,6]]

Output:

[4,5,6,7,8,9]

The buggy code pulls 9 back into the heap after the first round.

Constraints

  • 0 ≤ values.length ≤ 10,000

Learn the idea first: Heap sort, a visual lesson.

More Heap sort problems