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.
Check if a pump has more petrol than the kilometer (1st condition)
Test that pump. If during the tour, the remaining fuel >= 0 (2nd condition)
Return index of the pump that passed 2 conditions
note: remaining fuel = fuel - distance (kilometer)
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
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Truck Tour
You are viewing a single comment's thread. Return to all comments →
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