Question DSA-HEAP-0007
EasyWhat is the output of this code?
import heapq
h = []
for x in [3, 1, 2]:
heapq.heappush(h, x)
print([heapq.heappop(h) for _ in range(3)])
- A.
[2, 1, 3]
- B.
[3, 2, 1]
- C.
Show answer and explanation
Answer: C
Popping from a min-heap returns elements in increasing order.