• + 0 comments

    def truckTour(petrolpumps):

    petrolRest = [pump[0]-pump[1] for pump in petrolpumps] * 2
    
    for i in range(len(petrolpumps)):
    
        tank = 0
    
        for j in range(i, i + len(petrolpumps)):
    
            tank += petrolRest[j]
    
            if tank < 0: break     
    
        if tank < 0: continue
    
        else: return i
    
    return -1