forked from alexprut/HackerRank
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Solution.java
32 lines (28 loc) · 817 Bytes
/
Solution.java
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
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
static int minimumAbsoluteDifference(int n, int[] arr) {
Arrays.sort(arr);
int min = Integer.MAX_VALUE;
for (int i = 1; i < n; i++) {
if (Math.abs(arr[i-1] - arr[i]) < min) {
min = Math.abs(arr[i-1] - arr[i]);
}
}
return min;
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int[] arr = new int[n];
for(int arr_i = 0; arr_i < n; arr_i++){
arr[arr_i] = in.nextInt();
}
int result = minimumAbsoluteDifference(n, arr);
System.out.println(result);
in.close();
}
}