Given an integer n and an integer array rounds. We have a circular track which consists of n sectors labeled from 1 to n. A marathon will be held on this track, the marathon consists of m rounds. The ith round starts at sector rounds[i - 1] and ends at sector rounds[i]. For example, round 1 starts at sector rounds[0] and ends at sector rounds[1]

Return an array of the most visited sectors sorted in ascending order.

Notice that you circulate the track in ascending order of sector numbers in the counter-clockwise direction (See the first example).

&nbsp;
Example 1:

Input: n = 4, rounds = [1,3,1,2]
Output: [1,2]
Explanation: The marathon starts at sector 1. The order of the visited sectors is as follows:
1 --&gt; 2 --&gt; 3 (end of round 1) --&gt; 4 --&gt; 1 (end of round 2) --&gt; 2 (end of round 3 and the marathon)
We can see that both sectors 1 and 2 are visited twice and they are the most visited sectors. Sectors 3 and 4 are visited only once.

Example 2:

Input: n = 2, rounds = [2,1,2,1,2,1,2,1,2]
Output: [2]


Example 3:

Input: n = 7, rounds = [1,3,5,7]
Output: [1,2,3,4,5,6,7]


&nbsp;
Constraints:


	2 &lt;= n &lt;= 100
	1 &lt;= m &lt;= 100
	rounds.length == m + 1
	1 &lt;= rounds[i] &lt;= n
	rounds[i] != rounds[i + 1] for 0 &lt;= i &lt; m


class Solution:
    def mostVisited(self, n: int, rounds: List[int]) -> List[int]:
        hash_map = {}
        for i in range(0 , len(rounds)-1):
            if i == 0:
                start = rounds[i]
            elif rounds[i] == n:
                start = 1
            else:
                start = rounds[i] + 1
            end = rounds[i+1]
            if start <= end:
                for i in range(start , end + 1):
                    if i in hash_map:
                        hash_map[i] += 1
                    else:
                        hash_map[i] = 1
            else:
                for i in range(start , n + 1):
                    if i in hash_map:
                        hash_map[i] += 1
                    else:
                        hash_map[i] = 1
                for i in range(1 , end + 1):
                    if i in hash_map:
                        hash_map[i] += 1
                    else:
                        hash_map[i] = 1
        k = list(hash_map.keys())
        v = list(hash_map.values())
        ans = []
        m = -1
        i = 0
        j = 0
        while i < len(k) and j < len(v):
            if len(ans) == 0:
                ans.append(k[i])
                m = v[j]
            elif m < v[j]:
                ans = []
                ans.append(k[i])
                m = v[j]
            elif m == v[j]:
                ans.append(k[i])
            i += 1
            j += 1
        ans = sorted(ans)
        return ans
class Solution {
    public List<Integer> mostVisited(int n, int[] rounds) {
        int[]psum=new int[n+2];
        psum[rounds[0]]+=1;
        psum[rounds[1]+1]-=1;
        if(rounds[0]>rounds[1])
            psum[1]+=1;
        for(int i=2;i<rounds.length;i++){
            psum[rounds[i-1]+1]+=1;
            psum[rounds[i]+1]-=1;
            if(rounds[i-1]>rounds[i])
                psum[1]+=1;
        }
        int max_=0;
        for(int i=1;i<=n;i++){
            psum[i]+=psum[i-1];
            if(psum[i]>max_)
                max_=psum[i];
        }
        List<Integer>ans=new ArrayList<>();
        for(int i=1;i<=n;i++){
            if(psum[i]==max_)
                ans.add(i);
        }
        return ans;
    }
}
class Solution {
public:
    vector<int> mostVisited(int n, vector<int>& rounds) {
        vector <int> ans;
        int size = rounds.size();
        
        if(rounds[0] <= rounds[size-1]) {
            for(int i=rounds[0]; i<= rounds[size-1]; i++) {
                ans.push_back(i);
            }
            return ans;
        }
        else {
            for(int i=1; i<= rounds[size-1]; i++) {
                ans.push_back(i);
            }   
            
            for(int i=rounds[0]; i<=n; i++) {
                ans.push_back(i);
            }
        }
        
        return ans;
    }
};
var mostVisited = function(n, rounds) {
    const first = rounds[0];
    const last = rounds[rounds.length - 1];
   
    const result = [];
   
    if (first <= last) {
        for (let i = last; i >= first; i--) result.unshift(i)
    } else {
        for (let i = 1; i <= last; i++) result.push(i);
        for (let i = first; i <= n; i++) result.push(i);
    }
   
    return result;
};
Most Visited Sector in  a Circular Track