-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathProgram.cs
32 lines (25 loc) · 898 Bytes
/
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
using System;
namespace Minimum_Distances {
class Program {
public static int MinimumDistances(int[] ar) {
int minDistance = -1;
for (int i = 0; i < ar.Length; i++) {
for (int j = i + 1; j < ar.Length; j++) {
if (ar[i] == ar[j]) {
if (minDistance == -1 || minDistance > (j - i)) {
minDistance = (j - i);
}
break;
}
}
}
return minDistance;
}
static void Main(string[] args) {
int n = Convert.ToInt32(Console.ReadLine());
int[] ar = Array.ConvertAll(Console.ReadLine().Split(' '), aTemp => Convert.ToInt32(aTemp));
int result = MinimumDistances(ar);
Console.WriteLine(result);
}
}
}