1560. Most visited sector in a circular track
\n\n# Intuition\nThe problem is about finding the most visited sectors on a circular track. Starting from the initial sector and moving counter-clockwise, we id
![Screenshot 2024-09-07 175723.png](https://assets.leetcode.com/users/images/5371400b-1b2a-418f-8c3f-2b34ad7b6624_1725712064.8021276.png)\n\n# Intuition\nThe problem is about finding the most visited sectors on a circular track. Starting from the initial sector and moving counter-clockwise, we identify the sectors between the start and end points of the last round as the most visited. If the (start <= end), we directly take the sectors in between. If the (start >= end), we collect sectors from the start to the end, considering the wrap-around of the circular track.\n\n# Approach\n1 ) Declare empty vector ans to store the most visited sectors.\n2 ) identify the starting sector of the marathon from the first element of the rounds array (rounds[0]).\nWe identify the ending sector of the marathon from the last element of the rounds array (rounds[rounds.size()-1]).\n3 ) ( start <= end ), sectors visited in the last round are in a continuous sequence without wrapping around.\n4 ) loop ,  start <= end  end, we push all sectors from start to end into the ans vector, since they are visited in a straight path.\n5 ) else , This block handles the case where the track is circular and the start >= end . we need to account for wrapping around the track.\n6 ) First loop, push sectors from 1 to end into the ans vector because the marathon wraps around the track and reaches sector end.\n7 ) second loop, push sectors from start to n into the ans vector, the marathon starts at sector start and continues up to the last sector n.\n\n<!-- # Complexity -->\n- <b>Time complexity :</b>   O(n) visiting all sectors on the track once !\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- <b>Space complexity :</b> O(n) store all the sectors in the ans !\n\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    vector<int> mostVisited(int n, vector<int>& rounds) {\n    vector<int>ans;\n    int start = rounds[0];\n    int end = rounds[rounds.size()-1];\n\n    if (start <= end) {\n        for (int i = start; i <= end; i++) {\n            ans.push_back(i);\n        }\n    }else {\n        for (int i = 1; i <= end; i++) {\n            ans.push_back(i);\n        }\n        for (int i = start; i <= n; i++) {\n            ans.push_back(i);\n        }\n    }\n    return ans;\n    }\n};\n```
['C++']