FreeCareerPath
Build the PrimitiveMedium

Gas Station

Write `can_complete_circuit(gas, cost)` returning the starting index from which you can drive the whole circle, or `-1`. You start with an empty tank. gas = [1,2,3,4,5], cost = [3,4,5,1,2] -> 3 If the total gas is at least the total cost, a solution exists and it is unique. One pass: whenever the running tank goes negative, no station from the old start through here can work, so restart at the next one. Be ready to prove that — it is the entire question.

What to expect: A timer starts when you begin. Edit the starter code, run it against the test suite as many times as you like, then finish when you're done. The reference solution and interviewer follow-up questions unlock only after you finish.

Log in to start this session

Timed sessions and your results for "Gas Station" are saved to your account — logging in takes a few seconds.

Gas Station — FreeCareerPath