Question DSA-GRDY-0015
HardWhat is the output of this code?
gas, cost = [1, 2, 3, 4, 5], [3, 4, 5, 1, 2]
tank = start = total = 0
for i in range(len(gas)):
total += gas[i] - cost[i]
tank += gas[i] - cost[i]
if tank < 0:
start, tank = i + 1, 0
print(start if total >= 0 else -1)
- A.
4
- B.
0
- C.
Sign up free to see the answer and a step-by-step explanation.