134. Gas Station
Practice Gas Station for free on NudgeCode: Medium, Greedy pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.
There are n gas stations on a circular road. Station i gives you gas[i] units of fuel, and driving from station i to station i + 1 (the last one leads back to station 0) uses cost[i] units. Your tank starts empty and has no limit. Return the index of the station where you can start and drive the full loop once, or -1 if no start works. When an answer exists it is unique.
Example
gas = [1,2,3,4,5], cost = [3,4,5,1,2] -> 3
gas = [2,3,4], cost = [3,4,3] -> -1
Constraints
- 1 <= n <= 10^5
- 0 <= gas[i], cost[i] <= 10^4