Approach hintTry it first, then revealHide
A solution exists exactly when total gas is at least total cost. Scan once and move the candidate start to the next station whenever the running tank becomes negative.
A solution exists exactly when total gas is at least total cost. Scan once and move the candidate start to the next station whenever the running tank becomes negative.