You are viewing a single comment's thread. Return to all comments →
Python3 with nested loops. Passes all test cases.
def truckTour(petrolpumps): if len(petrolpumps) == 1: return 0 for start in range(len(petrolpumps)): tank, dist = petrolpumps[start] complete = True if tank < dist: continue else: tank -= dist if start == len(petrolpumps) - 1: i = 0 else: i = start + 1 while i != start: tank += petrolpumps[i][0] dist = petrolpumps[i][1] if tank < dist: complete = False break else: tank -= dist if i == len(petrolpumps) - 1: i = 0 else: i += 1 if complete: return start
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 →
Python3 with nested loops. Passes all test cases.