Question DSA-HEAP-0044
MediumWhat is the output of this code?
import heapq
sticks = [2, 4, 3]
heapq.heapify(sticks)
cost = 0
while len(sticks) > 1:
a, b = heapq.heappop(sticks), heapq.heappop(sticks)
cost += a + b
heapq.heappush(sticks, a + b)
print(cost)
- A.
16
- B.
14
- C.
Sign up free to see the answer and a step-by-step explanation.