If total gas < total cost, impossible. Otherwise there is a unique valid start (by greedy).
Scan stations with tank += gas[i]-cost[i].
If tank drops below 0, you cannot start anywhere in the current segment; reset start to i+1 and tank to 0.
At end, if total >= 0, return start.
A negative prefix tank means any start within that prefix would have even less fuel at the failure point, so all are invalid.
If total gas < total cost, impossible. Otherwise there is a unique valid start (by greedy).
Scan stations with tank += gas[i]-cost[i].
If tank drops below 0, you cannot start anywhere in the current segment; reset start to i+1 and tank to 0.
At end, if total >= 0, return start.
A negative prefix tank means any start within that prefix would have even less fuel at the failure point, so all are invalid.