Circular Route Query Distance
A circular route has n stops numbered from 0 to n - 1. The array distances has length n, where distances[i] is the distance from stop i to stop (i + 1) % n.
You are given several route queries. Each query [start, end] asks for the shorter of the two possible distances between those stops on the circle. Return the sum of the shortest distances over all queries.
1Example 1
The shortest distances are 1, 5, and 4, so the total is 10.
2Example 2
For 0 to 2, the counter-clockwise route is shorter with distance 13. For 2 to 1, the opposite direction has distance 10.
Constraints
Limits and guarantees your solution can rely on.
Stops are zero-indexed. Each query contains two valid stop indices. No numeric limits were provided in the source; an efficient solution should precompute prefix sums around the circle.