Question DSA-HEAP-0012
MediumWhat is the output of this code?
import heapq
a, k = [7, 10, 4, 3, 20, 15], 4
h = []
for x in a:
heapq.heappush(h, x)
if len(h) > k:
heapq.heappop(h)
print(h[0])
- A.
4
- B.
7
- C.
Sign up free to see the answer and a step-by-step explanation.