Question DSA-QUE-0042
MediumWhat is the output of this code?
from collections import deque
q = deque(["P1", "P2", "P3"])
left = {"P1": 5, "P2": 2, "P3": 4}
order = []
while q:
p = q.popleft()
left[p] -= 2
if left[p] > 0:
q.append(p)
else:
order.append(p)
print(order)
- A.
['P2', 'P3', 'P1']
- B.
['P3', 'P2', 'P1']
- C.
['P1', 'P2', 'P3']
- D.
['P2', 'P1', 'P3']
Sign up free to see the answer and a step-by-step explanation.