Question DSA-HEAP-0004
EasyWhat is the output of this code?
import heapq
h = [5, 3, 8, 1]
heapq.heapify(h)
print(h[0])
- A.
3
- B.
8
- C.
Show answer and explanation
Answer: C
heapq maintains a min-heap, so heap[0] is the smallest element.
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Heaps and Priority Queues question
What is the output of this code?
import heapq
h = [5, 3, 8, 1]
heapq.heapify(h)
print(h[0])
3
8
Answer: C
heapq maintains a min-heap, so heap[0] is the smallest element.
1
5