My code beats 100%
Intuition\nThis code solves the problem of finding the shortest distance between two bus stops on a circular route. The bus stops are connected in a circular ma
# Intuition\nThis code solves the problem of finding the shortest distance between two bus stops on a circular route. The bus stops are connected in a circular manner, meaning after the last stop, the route continues back to the first stop.\n\nGiven:\n\nA vector distance that holds the distance between each consecutive bus stop.\nTwo indices, start and destination, representing the starting and ending bus stops.\nThe goal is to compute the shortest distance between these two stops on this circular route\n\n# Approach\nCircular Distance Calculation: The circular nature of the bus route allows two possible directions:\n\nMoving clockwise from start to destination.\nMoving counterclockwise from destination back to start.\nCalculate Clockwise Distance (dist1):\n\nStart from the start bus stop.\nMove sequentially (in a clockwise manner) through the stops, adding the distances between consecutive stops.\nStop when you reach the destination.\nCalculate Counterclockwise Distance (dist2):\n\nStart from the destination bus stop.\nMove sequentially (in a counterclockwise manner) through the stops.\nAdd the distances between consecutive stops until you reach the start.\nEarly Exit Optimization:\n\nIf at any point during the calculation of dist2 (counterclockwise distance), dist2 becomes greater than dist1 (clockwise distance), there\'s no need to continue. Since we\'re looking for the shortest distance, we can immediately return dist1.\nFinal Comparison:\n\nIf the loop finishes without an early exit, then the counterclockwise distance (dist2) is the shortest, and the function returns that value.\n\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(1)\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    int distanceBetweenBusStops(vector<int>& distance, int start, int destination) {\n        int i=start;\n        int dist1=0;\n        while(i!=destination)\n        {\n            dist1+=distance[i];\n            i=(i+1)%distance.size();\n        }\n\n        i=destination;\n        int dist2=0;\n        while(i!=start)\n        {\n            if(dist2<dist1)\n            {\n                 dist2+=distance[i];\n                  i=(i+1)%distance.size();\n            }\n            else \n                return dist1;\n            \n           \n        }\n\n\n        return dist2;\n    }\n};\n```
['C++']