🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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?

  1. A.Call heapq.maxheap()
  2. B.Pass reverse=True to heappush
  3. C.Push negative numbers and negate them again when popping
  4. 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 →