n fuel stations around a circular track, numbered from 0 in the driving direction. At station i you can take fuel[i] units of fuel, and the road from it to the next station (from the last one back to station 0) burns burn[i] units. The tank has no limit and starts empty.
Return the index of the station you can start from and drive a full lap without the fuel ever going negative. If there is no such station, return -1.
If a suitable station exists, it is guaranteed to be unique.
Trying every start takes O(n²); aim for a single pass.fuel=[2, 6, 1, 5], burn=[3, 2, 6, 2] → 3
Start at station 3: the tank holds 5 − 2 = 3, then 3 + 2 − 3 = 2, then 2 + 6 − 2 = 6, then 6 + 1 − 6 = 1, and the lap is done. From any other station the tank runs dry somewhere.
fuel=[3, 1, 2], burn=[2, 3, 2] → -1
There are 6 units of fuel in total but the lap needs 7, so no start works.
fuel=[5], burn=[5] → 0
A single station: you take 5 and spend exactly that to drive back to it.
fuel=[2, 6, 1, 5], burn=[3, 2, 6, 2]
3
Run checks the first 3 tests in your browser. Submit checks all 47 tests on the server, hidden ones included.