pls help solve the debug error
Petrol pump problem
@A17LP0014 hey there is some problem in calculation check this funtion code ,made some changes:
int canCompleteCircuit(int[] gas, int[] cost) {
int total = 0 ;
int cur = 0 ;
int s= 0;
for(int i = 0 ; i < gas.length ; i++){
total = total + gas[i] - cost[i];
cur += gas[i] - cost[i];
if(cur<0){
cur = 0 ;
s = i+1 ;
}
}
if(total >= 0 )
return s;
else
return -1;
}
It is there already, there must be some other error
@A17LP0014 bhai apki total cost nikalne me dikkt arhi hai ek bar check kro apne bracket galat dali hai ,rest your logic is correct ,yhi problem mene thek ki hai above code me.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.