There are n gas stations in a circle. gas[i] is the gas available, cost[i] is the gas to travel to the next station. If you can complete the circuit, return the starting index. Otherwise return -1.
Input: gas = [1,2,3,4,5], cost = [3,4,5,1,2]
Output: 3
Topics: greedy, arrays
Asked by: Amazon, Google, Meta, Microsoft, Bloomberg
Time complexity: O(n). Space complexity: O(1).