C++ Solutions
Synopsis:\n Let i be the start index and j be the end index\n The answer is the minimum of the clockwise traversal from i to j and the counter-clockwise travers
**Synopsis:**\n* Let i be the start index and j be the end index\n* The answer is the minimum of the clockwise traversal from i to j and the counter-clockwise traversal from j to i\n\n**Note:**\n* The distance to go clockwise from i to i+1 is A[i]\n* The distance to go counter-clockwise from i to i-1 is A[i-1]\n\n**Verbose Solution:**\n```\nclass Solution {\npublic:\n    int distanceBetweenBusStops(vector<int>& A, int i, int j) {\n        if (j < i) {\n            swap(i, j);\n        }\n        return min(accumulate(A.begin() + i, A.begin() + j, 0), accumulate(A.begin() + j, A.end(), 0) + accumulate(A.begin(), A.begin() + i, 0));\n    }\n};\n```\n\n**Supplemental:** using iterators can help make this code more clear and using lambda functions improves semantics due to first-class concepts\n\n*using iterators...*\n```\nclass Solution {\npublic:\n    int distanceBetweenBusStops(vector<int>& A, int i, int j) {\n        if (j < i) {\n            swap(i, j);\n        }\n        auto beg = A.begin() + i,\n             end = A.begin() + j;\n        return min(accumulate(beg, end, 0), accumulate(end, A.end(), 0) + accumulate(A.begin(), beg, 0));\n    }\n};\n```\n\n*using lambda functions...*\n```\nclass Solution {\npublic:\n    using VI = vector<int>;\n    int distanceBetweenBusStops(VI& A, int i, int j) {\n        if (j < i) {\n            swap(i, j);\n        }\n        auto clockwise = [&](int i, int j) {\n            return accumulate(A.begin() + i, A.begin() + j, 0);\n        };\n        auto counter_clockwise = [&](int i, int j) {\n            return accumulate(A.begin() + j, A.end(), 0) + accumulate(A.begin(), A.begin() + i, 0);\n        };\n        return min(clockwise(i, j), counter_clockwise(i, j));\n    }\n};\n```\n\n**Concise Solution:**\nUsing the same concept as above solutions, either choose the path with the route from i to j ( ie. go clockwise ) xor the path without that route ( ie. go counter-clockwise ), whichever is minimal.\n```\nclass Solution {\npublic:\n    using VI = vector<int>;\n    int distanceBetweenBusStops(VI& A, int i, int j) {\n        if (j < i) {\n            swap(i, j);\n        }\n        auto route = accumulate(A.begin() + i, A.begin() + j, 0),\n             total = accumulate(A.begin(), A.end(), 0);\n        return min(route, total - route);\n    }\n};\n```
[]