Question DSA-HEAP-0016
HardWhat is the output of this code?
import heapq
lo, hi, out = [], [], []
for x in [1, 2, 3]:
heapq.heappush(lo, -x)
heapq.heappush(hi, -heapq.heappop(lo))
if len(hi) > len(lo):
heapq.heappush(lo, -heapq.heappop(hi))
out.append(float(-lo[0]) if len(lo) > len(hi) else (-lo[0] + hi[0]) / 2)
print(out)
- A.
[1, 2, 3]
- B.
[1.0, 1.5, 2.0]
- C.
Sign up free to see the answer and a step-by-step explanation.