Problems > Around the Circuit > Editorial

Around the Circuit — Solution & Editorial

Back to the Problem

If total gas ≥ total cost a solution exists. Sweep once: whenever the running tank goes negative, no station in the failed stretch can start — restart just after it.

Complexity: O(N)