Distance Between Bus Stops Problem

Distance Between Bus Stops Problem — ExecCode Easy DSA Practice

Solve the Distance Between Bus Stops problem on ExecCode. Free online easy DSA practice in Arrays - Logic Building. Write and run code in Java, C++, Python — no signup required to run.

Problem description

Description You are given the input needed to solve Distance Between Bus Stops. Your task is to compute the required answer and return the shortest distance between the given start and destination stops. 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.

Examples

Input {"distance": [1, 2, 3, 4], "start": 0, "destination": 1}; Output 1. Input {"distance": [1, 2, 3, 4], "start": 0, "destination": 2}; Output 3

Constraints

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

Practice Distance Between Bus Stops free on ExecCode. Browse DSA problems, topic map, and placement guides.