 All Problems
Gas Station
medium
arrays
greedy
amazon
google
microsoft
facebook

There are n gas stations in a circle. You are given gas[i] and cost[i] (to travel from station i to i+1). Find the starting station index to complete the circuit, or return -1 if impossible. The solution is guaranteed to be unique if it exists.

Example:

Input:
1 2 3 4 5
3 4 5 1 2
Output: 3

Input format: Line 1 = gas, line 2 = cost (space-separated).

Run to check your code against the sample cases, or submit to run every case