educative.io

Educative

Why are we inserting -num to the maxHeap?

In the first if statement in insert()

1 Like

Hi @Malachi_Shoffner,

We are inserting -num to build a max heap. The default implementation is for the min-heap, to make it max-heap we make each number negative.

3 Likes

Thanks!