Tap here to switch tabs
Problem
Submissions

Problem: Distance Between Bus Stops

med
30 min
Try to solve the Distance Between Bus Stops problem.

Statement

A bus route has n stops numbered from 00 to n −1- 1 arranged along a circle. You are given an integer array distance where distance[i] represents the distance between stop i and stop (i+1) mod (i + 1) \bmod n.

The bus can travel in either a clockwise or counterclockwise direction. Return the shortest distance between the given start and destination stops.

Constraints:

  • 1≤1 \leq n ≤104\leq 10^4

  • distance.length =n= n

  • 0≤0 \leq start, destination <n< n

  • 0≤0 \leq distance[i] ≤104\leq 10^4

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Distance Between Bus Stops

med
30 min
Try to solve the Distance Between Bus Stops problem.

Statement

A bus route has n stops numbered from 00 to n −1- 1 arranged along a circle. You are given an integer array distance where distance[i] represents the distance between stop i and stop (i+1) mod (i + 1) \bmod n.

The bus can travel in either a clockwise or counterclockwise direction. Return the shortest distance between the given start and destination stops.

Constraints:

  • 1≤1 \leq n ≤104\leq 10^4

  • distance.length =n= n

  • 0≤0 \leq start, destination <n< n

  • 0≤0 \leq distance[i] ≤104\leq 10^4