public int canCompleteCircuit(int[] gas, int[] cost) {
        // Note: The Solution object is instantiated only once and is reused by each test case.
        int stations[] = new int[gas.length];
        int sum = 0;
        for (int i = 0; i < stations.length; i++)
        {
        	stations[i] = gas[i] - cost[i];
        	sum += stations[i];
        }
        if (sum < 0)
        	return -1;
        
        int start = 0;
        while (start < stations.length)
        {
        	if (stations[start] < 0)
        		start++;
        	else
        	{
        		int s = stations[start];
        		int idx = start + 1; 
        		while (s >= 0 && idx % (stations.length) != start)
        		{
        			s += stations[idx %(stations.length)];
        			idx++;
        		}
        		
        		if (s < 0)
        			start = idx;
        		else
        			return start;
        	}
        }
        
        return -1;
    }