function mostVisited(n, rounds){
let arr = Array(n+1).fill(0);
let answer = [];
let len = rounds.length;
for(let i = 0; i < len-1; i++){
if(rounds[i] < rounds[i+1]){
for(let j = rounds[i]; j < rounds[i+1]; j++){
arr[j]++;
}
}else{
for(let j = rounds[i]; j <= n; j++){
arr[j]++;
}
for(let j = 1; j < rounds[i+1]; j++){
arr[j]++;
}
}
}
arr[rounds[len-1]]++;
let a = Math.max(...arr);
for(let i = 1; i < n+1; i++){
if(arr[i] == a){
answer.push(i);
}
}
return answer;
}
let n = 7, rounds = [1,3,5,7]