Gas Station

Medium
ArrayGreedyAmazonGoogle
There are n gas stations in a circle. At station i, you gain gas[i] fuel and spend cost[i] fuel to drive to the next station. Print the smallest starting index that completes the circuit, or -1 if impossible. Input format: - First line: n - Second line: n gas values - Third line: n cost values

Constraints

1 <= n <= 10^5
0 <= gas[i], cost[i] <= 10^9

Sample tests

Sample 1

Sample 2

Sign in to submit