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