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.
for i in range(n):
petrol, distance = petrolpumps[i]
current_petrol += petrol - distance
total_petrol += petrol - distance
if current_petrol < 0:
start_index = i + 1
current_petrol = 0
return start_index if total_petrol >= 0 else -1
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 →
Easy python solution-
def truckTour(petrolpumps): n = len(petrolpumps) current_petrol = 0 total_petrol = 0 start_index = 0