educative.io

Confusing "Finally, if the array of the top element has more elements, we’ll insert the next element to the heap."

Finally, if the array of the top element has more elements, we’ll insert the next element to the heap.

More elements than?
What is top element here?
There is just this condition
if (list.length > i + 1) {

There is no condition in code to correspond to above statement.

Can anyone help me?

They are referring to the element that was just popped from the heap. You can see them reference it as the “top” element below.
“In a loop, we’ll take the smallest (top) element from the min-heap”

That statement would correlate to the below line:
if len(arr) > i+1:

1 Like

“If the array of the top element has remaining elements” would be more clear.