LearnFrenzy
Sign in Take a free test

Python Coding Interview Questions · Coding Interview Concepts MCQ · Question 3

What kind of heap is heapq? Answer, explanation & discussion

  • MCQ
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 3 Back to Exercise

After pushing 5, 1 and 9 with heapq.heappush, what does heappop return first?

  • A 9 – heapq is a max-heap
  • B 5 – it is a queue
  • C 1 – heapq is a min-heap Correct
  • D A random element
Correct Answer: Option C

Negate values (or use nlargest) to get max-heap behaviour.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links