-
Notifications
You must be signed in to change notification settings - Fork 7
/
Program.cs
39 lines (38 loc) · 1.1 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System;
using System.Collections.Generic;
using System.Linq;
namespace MostVisitedSectorInACircularTrack
{
class Program
{
static void Main(string[] args)
{
int n = 4;
int[] rounds = {1, 3, 1, 2};
Console.WriteLine(MostVisited(n, rounds));
}
static IList<int> MostVisited(int n, int[] rounds)
{
var visits = new int[n + 1];
visits[rounds[0]]++;
for (int i = 1; i < rounds.Length; i++)
{
int start = rounds[i - 1] + 1;
int end = rounds[i] < rounds[i - 1] ? rounds[i] + n : rounds[i];
for (int j = start; j <= end; j++)
{
int index = j < visits.Length ? j : j - n;
visits[index]++;
}
}
var max = visits.Max();
var res = new List<int>();
for (int i = 0; i < visits.Length; i++)
{
if(visits[i] == max)
res.Add(i);
}
return res;
}
}
}