class Solution:
def canCompleteCircuit(self, gas: List[int], cost: List[int]) -> int:
""" time O(N) space O(1)
1. loop through gas, cost array, get total gas, total cost
2. during iteration, check current tank < 0, if yes, reset current tank, start from i + 1
3. check if total cost <= total gas
"""
n = len(gas)
sumCost = 0
sumGas = 0
start = 0
tank = 0
for i,(g,c) in enumerate(zip(gas,cost)):
sumCost += c
sumGas += g
tank += g - c
if tank < 0:
start = i + 1
tank = 0
if sumCost > sumGas:
return -1
return start