We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Data Structures
- Queues
- Truck Tour
- Discussions
Truck Tour
Truck Tour
Sort by
recency
|
363 Discussions
|
Please Login in order to post a comment
The problem is misleading, as it does not crearly states that there will always be a solution. You are led to believe to check if you go the full circle. You usually are taught to think of all scenarios, including no solution. So this was a very vague problem description. Finally, I was able to do it by using a prefix list in O(n) time, by using tabulation to optimize checking all the posible circles.
Imo this is very easy
The challenge is how to test 2nd condition. If you want to test a pump number 2, than it need to go through [2 > 3 > 4 > 5 > 1] if there is 5 pumps. If during testing and that specific pump's remaining fuel get to below 0 than skip that pump
Yeah it pretty easy , when taking coding challenges we always tend to think of alternative more clever way than the basic brute force approach , but in most cases that is the raison why we spend more time for and at the end brute force is easy win .
it is nevertheless a not very generalizable problem and thats why in this case, brute force seems a good alternative. There are not inputs whose solutions are: there is no way of making this circle. Thus, when you assess if each pump has the petrol equivalent to the distance to the next pump, it is just about picking the smaller.
def truckTour(petrolpumps):
Python Solution