# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---







while start != destination:
    nxt = start + 1
    min_distance += min(distance[start], sum_val - distance[nxt])
    start = nxt
return min_distance


class Solution:
    def distanceBetweenBusStops(self, distance, start: int, destination):
        if start == destination:
            return 0
        
        presum = [0]
        for n in distance:
            presum.append(n + presum[-1])
        sum_val = sum(distance)
        dist = abs(presum[destination] - presum[start])
        return min(dist, sum_val - dist)


solution = Solution()
solution.distanceBetweenBusStops([7,10,1,12,11,14,5,0], 7, 2)



StarcoderdataJupyterScriptsDedupFiltered