This question needs more clarification


  • 1
    B

    The question asks if a trip can be made successfully, but it leaves out the definition of successfully. In an interview, I would ask the following questions (heck, I want the following questions answered by anyone before I even continue on this problems):

    1. Would the idea be to complete a circuit and keep the cost below 1 unit per distance?
    2. Can there be negative costs (so we can earn money)?
    3. How big can the number of stations be?

    The last two questions can be easily deduced from the online judge if one has patients. But the first question is essential to this problem.

    Does anyone have insight?


  • 0
    S
    1. I do not understand your question actually. You may misunderstand the cost[i]. The cost[i] is the cost of gas, not money. From station i to station i+1, you can fuel the car with gas[i] unit of gas, then it will cost cost[i] unit of gas to station i+1.
    2. costs is always positive.
    3. You can solve the problem as sufficient as you can. For example, if you implement in a O(N^2) solution, you get time limit exceed, you might think about a better solution. I think when you having interview, the best solution may come out iteratively. If interviewee tell you the test case scale, it maybe a cheat to come up the best solution.

Log in to reply
 

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