-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNearestMin.java
More file actions
38 lines (35 loc) · 1.13 KB
/
NearestMin.java
File metadata and controls
38 lines (35 loc) · 1.13 KB
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
/**
* Created by MalhotR1 on 01/05/2018.
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class NearestMin {
public static void main(String[] args) throws IOException {
try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
int N = Integer.parseInt(br.readLine().trim());
String[] in = br.readLine().trim().split(" ");
long[] arr = new long[N];
long min = Long.MAX_VALUE;
int dis = 0;
int temp = Integer.MAX_VALUE;
for (int i = 0; i < N; i++) {
arr[i] = Long.parseLong(in[i]);
if (min > arr[i]) {
min = arr[i];
dis = 0;
temp = 0;
} else if (min == arr[i]) {
temp++;
if (dis == 0) dis = temp;
else dis = Math.min(dis, temp);
temp = 0;
}
else {
temp++;
}
}
System.out.println(dis);
}
}
}