```
class Solution {
```

public:

int canCompleteCircuit(vector<int> &gas, vector<int> &cost) {

```
int n = gas.size();
int balance=0;
int index=0;
int neg=0;
for(int i=0;i<n;i++)
{
balance+=gas[i];
balance-=cost[i];
if(balance<0)
{
index=i+1;
neg+= (-balance);
balance=0;
}
}
balance-=neg;
if(balance>=0)
return index;
else
return -1;
}
```

};