Gas Station Circular Tour
Problem statement
Petrol pumps numbered 0 through n - 1 lie on a circular route. Pump i provides gas[i] litres, and reaching the next pump consumes cost[i] litres. Your truck starts with an empty tank of unlimited capacity and collects the fuel at every pump it visits.
Return the smallest pump index from which the truck can complete one full clockwise circuit without its tank becoming negative. Return -1 if no starting pump works. Fuel may reach exactly zero.
Function
gasStation(gas: int[], cost: int[]) → intExamples
Example 1
gas = [1,2,3,4,5]cost = [3,4,5,1,2]return = 3Pump three accumulates enough fuel to cross the earlier deficits.
Example 2
gas = [2,3,4]cost = [3,4,3]return = -1Total fuel is smaller than total travel cost.
Constraints
1 <= gas.length = cost.length <= 10^5.0 <= gas[i], cost[i] <= 10^9.