segments[i] is the length of the track between station i and station (i + 1) mod n.
Return the length of the shortest trip from station start to station finish. If they are the same station, the answer is 0.segments=[3, 8, 2, 5], start=1, finish=3 → 8
Clockwise: 8 + 2 = 10; counterclockwise: 3 + 5 = 8. The answer is 8.
segments=[6, 1, 4], start=2, finish=0 → 4
From station 2 to station 0 it is 4 along the direct segment, or 6 + 1 = 7 the other way.
segments=[7, 7], start=1, finish=1 → 0
segments=[3, 8, 2, 5], start=1, finish=3
8
Run checks the first 3 tests in your browser. Submit checks all 71 tests on the server, hidden ones included.