cheetcode

125. Gas StationMedium

Find the starting gas station index that lets you complete the circuit.

There are n gas stations around a circular route. At station i, gas[i] is the amount of gas available and cost[i] is the gas needed to travel to the next station.

Return the starting station index if you can travel around the circuit once, otherwise return -1.

Examples

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

Constraints

  • 1 <= gas.length == cost.length <= 100,000
  • 0 <= gas[i], cost[i] <= 10,000