← Quiz: Sorting, heapq and bisect: all 10 questions
Quiz: Sorting, heapq and bisect · Question 6 of 10
How do you get a max-heap with heapq?
How do you get a max-heap with heapq?
- A.Call heapq.maxheap()
- B.Pass reverse=True to heappush
- C.Push negative numbers and negate them again when popping
- D.Sort the list in reverse first
Answer & explanation
Correct answer: Push negative numbers and negate them again when popping
heapq is a min-heap only; negating turns the largest value into the smallest.
Can you get the rest right without peeking?
Take the timed Quiz: Sorting, heapq and bisect quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →