1184. Distance Between Bus Stops

https://leetcode.com/problems/distance-between-bus-stops

Description

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:

Example 2:

Example 3:

Constraints:

  • 1 <= n <= 10^4

  • distance.length == n

  • 0 <= start, destination < n

  • 0 <= distance[i] <= 10^4

ac

Last updated

Was this helpful?