Find starting gas station to complete a circular trip. Return -1 if impossible.

Input: gas=[1,2,3,4,5], cost=[3,4,5,1,2] → Output: 3 Input: gas=[2,3,4], cost=[3,4,3] → Output: -1

If total gas >= total cost, a solution exists. Track running tank; reset start when tank goes negative.

public int canCompleteCircuit(int[] gas, int[] cost) { int total = 0, tank = 0, start = 0; for (int i = 0; i < gas.length; i++) { int diff = gas[i] - cost[i]; total += diff; tank += diff; if (tank < 0) { start = i + 1; tank = 0; } } return total >= 0 ? start : -1; }