Can anyone answer why my code is not working
my code is not working.I couldn’t figure out what is my problem.Can somebody help me out?

Your code won’t work for test cases like 3 0 0 0 0 0 5 because the fuel will be over when you come till 4th car. So, the answer will be 3 only and not 8. Hope you got my logic.