Dodomeki
Sign in

110. Gas Station Circuit

Hard

There are gas stations arranged in a circuit. combustivel[i] gives the amount of gas at station i, and custo[i] gives the gas needed to reach the next station. The tank starts empty and has no capacity limit. Return the index of the starting station that allows you to complete one full circuit, or -1 if it is impossible. If there is more than one valid answer, return the smallest index.

Example 1
Input: combustivel = [2, 4, 1, 3], custo = [3, 1, 2, 3]
Output: 1
Example 2
Input: combustivel = [1, 2], custo = [2, 2]
Output: -1
Constraints
  • 1 <= combustivel.length == custo.length <= 10^5
  • 0 <= combustivel[i], custo[i] <= 10^9
GreedyArrays
Caso 1
combustivel =
[2,4,1,3]
custo =
[3,1,2,3]
Expected =
1
Caso 2
combustivel =
[1,2]
custo =
[2,2]
Expected =
-1

Run checks these 2 cases. Submit runs all 6, including hidden ones.