🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Heaps and Heap Sort Internals: all 15 questions

Quiz: Heaps and Heap Sort Internals · Question 14 of 15

How do you use Python's heapq as a max-heap of numbers?

How do you use Python's heapq as a max-heap of numbers?

  1. A.Call heapq.maxheap()
  2. B.Sort the list in reverse first
  3. C.Push the negated values and negate again when you pop
  4. D.It cannot be done
Answer & explanation

Correct answer: Push the negated values and negate again when you pop

The smallest negated value belongs to the largest original value.

Can you get the rest right without peeking?

Take the timed Quiz: Heaps and Heap Sort Internals quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →