An error in Run Code test?


  • 1
    C

    I use the following input to test my code :
    gas [4 0 1]
    cost [3 2 1]

    and the OJ show the expected answer is 2 instead of -1. Is this an error for the Run code test?


  • 0
    S

    Hi, i just tried the input test case you have mentioned in the question for the gas station problem. The OJ gives output -1 and not 2. Recheck it you might by mistake given other input case.


  • 0
    C

    It seems that this only happens to C++ version. I tried Java and Python and both the answers are correct .


  • 0
    This post is deleted!

  • 0

    Hi,

    I just realized that it is 2. Because if you start from 2, you can get to 1 by [2 0 1], after you got 1, you don't need to move on. You already finished it! So the OJ is correct, isn't it?


  • 0

    I thought it again, I'm totally confused.... If all of the other versions return -1, then it means the car has to get back to start point.


  • 0
    J

    I think in this problem, we need to go back to the starting station.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.