A bus&nbsp;has n stops numbered from 0 to n - 1 that form&nbsp;a circle. We know the distance between all pairs of neighboring stops where distance[i] is the distance between the stops number&nbsp;i and (i + 1) % n.

The bus goes along both directions&nbsp;i.e. clockwise and counterclockwise.

Return the shortest distance between the given&nbsp;start&nbsp;and destination&nbsp;stops.

&nbsp;
Example 1:



Input: distance = [1,2,3,4], start = 0, destination = 1
Output: 1
Explanation: Distance between 0 and 1 is 1 or 9, minimum is 1.

&nbsp;

Example 2:



Input: distance = [1,2,3,4], start = 0, destination = 2
Output: 3
Explanation: Distance between 0 and 2 is 3 or 7, minimum is 3.


&nbsp;

Example 3:



Input: distance = [1,2,3,4], start = 0, destination = 3
Output: 4
Explanation: Distance between 0 and 3 is 6 or 4, minimum is 4.


&nbsp;
Constraints:


	1 &lt;= n&nbsp;&lt;= 10^4
	distance.length == n
	0 &lt;= start, destination &lt; n
	0 &lt;= distance[i] &lt;= 10^4

class Solution:
    def distanceBetweenBusStops(self, distance: List[int], start: int, destination: int) -> int:
        # switch start and destination if destination is before start
        if start>destination:    
            start,destination=destination,start
        #find minimum for clockwise and counterclockwise direction
        return  min(sum(distance[start:destination]),sum(distance[:start]+distance[destination:]))
class Solution {
    public int distanceBetweenBusStops(int[] distance, int start, int destination) {
        int firstDistance = 0;
        int secondDistance = 0;
        if (start < destination) {
            //check clockwise rotation
            for (int i = start; i < destination; i++)
                firstDistance += distance[i];
            //check clockwise rotation from destination to end
            for (int i = destination; i < distance.length; i++)
                secondDistance += distance[i];
            //continues checking till start (if needed)
            for (int i = 0; i < start; i++)
                secondDistance += distance[i];
        }
        else {
            for (int i = start; i < distance.length; i++)
                firstDistance += distance[i];
            for (int i = 0; i < destination; i++)
                firstDistance += distance[i];
            for (int i = start - 1; i >= destination; i--)
                secondDistance += distance[i];
        }
        return Math.min(firstDistance, secondDistance);
    }
}
class Solution {
public:
    int distanceBetweenBusStops(vector<int>& distance, int start, int destination) {
        int n = distance.size();
        if (start == destination)
            return 0;

        int one_way = 0;
        int i = start;
        while (i != destination) // find distance of one way
        {
            one_way += distance[i];
            i = (i+1)%n;
        }
        
        int second_way = 0;
        i = destination;
        while (i != start) // find distance of second way
        {
            second_way += distance[i];
            i = (i+1)%n;
        }
        
        return one_way<second_way? one_way : second_way; // return the minimum
    }
};
/**
 * @param {number[]} distance
 * @param {number} start
 * @param {number} destination
 * @return {number}
 */
let sumArray = (arr) => {
    return arr.reduce((prev, curr) => prev + curr, 0)
}

var distanceBetweenBusStops = function(distance, start, destination) {
    let dist = sumArray(distance.slice((start < destination)?start:destination, (start < destination)?destination:start));
    return Math.min(dist, sumArray(distance) - dist)
};
Distance Between Bus Stops