← 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?
- A.Call heapq.maxheap()
- B.Sort the list in reverse first
- C.Push the negated values and negate again when you pop
- 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 →