A bus has n stops numbered from 0 to n - 1 that form a circle. We know the distance between all pairs of neighboring stops where distance[i] is the distance between the stops number i and (i + 1) % n.
The bus goes along both directions i.e. clockwise and counterclockwise.
Return the shortest distance between the given start and destination stops.
 
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.
 
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.

 
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.

 
Constraints:

1 <= n <= 10^4
distance.length == n
0 <= start, destination < n
0 <= distance[i] <= 10^4

Difficulty: EASY
Starter code: class Solution:
    def distanceBetweenBusStops(self, distance: List[int], start: int, destination: int) -> int:
        

Solutions:
class Solution:

	def distanceBetweenBusStops(self, distance: List[int], start: int, destination: int) -> int:
		if start > destination:
			(start, destination) = (destination, start)
		sum1 = sum(distance[start:destination])
		sum2 = sum(distance) - sum1
		return min(sum1, sum2)


class Solution:

	def distanceBetweenBusStops(self, distance: List[int], start: int, destination: int) -> int:
		clockwise = 0
		i = start
		while i != destination:
			clockwise += distance[i]
			if i == len(distance) - 1:
				i = 0
			else:
				i += 1
		i = start
		counterclockwise = 0
		while i != destination:
			if i == 0:
				i = len(distance) - 1
			else:
				i -= 1
			counterclockwise += distance[i]
		return min(clockwise, counterclockwise)


class Solution:

	def distanceBetweenBusStops(self, distance: List[int], start: int, destination: int) -> int:
		num = len(distance)
		if start <= destination:
			dis1 = sum(distance[start:destination])
			dis2 = sum(distance[destination:]) + sum(distance[:start])
		elif start > destination:
			dis1 = sum(distance[start:]) + sum(distance[:destination])
			dis2 = sum(distance[destination:start])
		return min(dis1, dis2)


class Solution:

	def distanceBetweenBusStops(self, distance: List[int], start: int, destination: int) -> int:
		total = sum(distance)
		journey = 0
		while start % len(distance) != destination:
			journey += distance[start % len(distance)]
			start += 1
		return min(journey, total - journey)


from typing import List
from math import pow

class Solution:

	def start_to_end_traverasal(self, distance: List[int], start: int, destination: int) -> int:
		n: int = len(distance)
		total: int = 0
		index: int = start
		end: int = int((destination - 1 + n) % n)
		while True:
			total += distance[index]
			if index == end:
				break
			else:
				index += 1
				if index == n:
					index = 0
		return total

	def end_to_start_traverasal(self, distance: List[int], start: int, destination: int) -> int:
		return self.start_to_end_traverasal(distance, destination, start)

	def distanceBetweenBusStops(self, distance: List[int], start: int, destination: int) -> int:
		n: int = len(distance)
		assert 1 <= n and n <= pow(10, 4)
		assert destination < n
		assert 0 <= start
		clockwise_total: int = self.start_to_end_traverasal(distance, start, destination)
		counterclockwise_total: int = self.end_to_start_traverasal(distance, start, destination)
		return min(clockwise_total, counterclockwise_total)


class Solution:

	def distanceBetweenBusStops(self, distance: List[int], start: int, destination: int) -> int:
		if start == destination:
			return 0
		if start > destination:
			(start, destination) = (destination, start)
		assert start != destination
		return min(sum(distance[start:destination]), sum(distance[:start] + distance[destination:]))


class Solution:

	def distanceBetweenBusStops(self, distance: List[int], start: int, destination: int) -> int:
		if start == destination:
			return 0
		elif start > destination:
			(start, destination) = (destination, start)
		cw = 0
		for i in range(start, destination):
			cw += distance[i]
		ccw = 0
		n = len(distance)
		for i in range(destination, start + n):
			ccw += distance[i % n]
		return min(cw, ccw)


class Solution:

	def distanceBetweenBusStops(self, distance: List[int], start: int, destination: int) -> int:
		if start == destination:
			return 0
		if start > destination:
			(start, destination) = (destination, start)
		increase = start
		decrease = start
		right = 0
		left = 0
		while True:
			index = increase % len(distance)
			increase += 1
			if index == destination:
				break
			right += distance[index]
		while True:
			decrease -= 1
			index = decrease % len(distance)
			left += distance[index]
			if index == destination:
				break
		return min(left, right)


class Solution:

	def distanceBetweenBusStops(self, distance: List[int], start: int, destination: int) -> int:
		s_d = 0
		d_s = 0
		d_sd = []
		if start < destination:
			d_sd = distance[start:destination]
		if start >= destination:
			d_sd = distance[:destination] + distance[start:]
		for x in range(len(d_sd)):
			s_d += d_sd[x]
		d_s = sum(distance) - s_d
		return min(s_d, d_s)


class Solution:

	def distanceBetweenBusStops(self, distance: List[int], start: int, destination: int) -> int:
		distance += [0]
		for i in range(len(distance) - 2, -1, -1):
			distance[i] += distance[i + 1]
		d = abs(distance[start] - distance[destination])
		return min(d, distance[0] - d)


class Solution:

	def distanceBetweenBusStops(self, distance: List[int], start: int, destination: int) -> int:
		n = len(distance)
		p1 = start % n
		p2 = destination % n
		d1 = 0
		d2 = 0
		while p1 != destination and p2 != start:
			d1 += distance[p1]
			d2 += distance[p2]
			p1 = (p1 + 1) % n
			p2 = (p2 + 1) % n
		if p1 == destination:
			return d1
		return d2


class Solution:

	def distanceBetweenBusStops(self, distance: List[int], start: int, destination: int) -> int:
		fdistance = 0
		sdistance = 0
		n = len(distance)
		for i in range(start, start + n):
			if i % n == destination:
				break
			fdistance += distance[i % n]
		for i in range(destination, destination + n):
			if i % n == start:
				break
			sdistance += distance[i % n]
		return fdistance if fdistance < sdistance else sdistance