86. Gas Station

Stations on a circular route give gas[i]; driving from station i to i + 1 costs cost[i]. Starting with an empty tank, return the station index from which you can drive once around the circuit, or -1. The answer is unique if it exists.

Example 1

Input: gas = [1,2,3,4,5], cost = [3,4,5,1,2]
Output: 3

Example 2

Input: gas = [2,3,4], cost = [3,4,3]
Output: -1
Hint 1

If total gas ≥ total cost, a solution exists.

Hint 2

If you run dry at station i, no station between the current start and i can be the answer.

Greedy