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