File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change
1
+ import java .io .*;
2
+
3
+ class Mini {
4
+
5
+ //Function to find minimum adjacent difference in a circular array.
6
+ // arr[]: input array
7
+ // n: size of array
8
+ public int minAdjDiff (int arr [], int n ) {
9
+ int min = Math .abs (arr [0 ] - arr [n -1 ]);
10
+
11
+ for (int i = 0 ;i <n -1 ;i ++){
12
+ min = Math .min (min ,Math .abs (arr [i ] - arr [i +1 ]));
13
+ }
14
+ return min ;
15
+ }
16
+ }
17
+
18
+
19
+ public class MinimumDiff {
20
+
21
+ public static void main (String [] args ) throws IOException {
22
+ BufferedReader br = new BufferedReader (new InputStreamReader (System .in ));
23
+ int t = Integer .parseInt (br .readLine ().trim ()); //Inputting the testcases
24
+
25
+ while (t -->0 )//While testcases exist
26
+ {
27
+ //Input size of array
28
+ int n = Integer .parseInt (br .readLine ().trim ());
29
+
30
+ //Array of size n
31
+ int arr [] = new int [n ];
32
+
33
+ String inputLine [] = br .readLine ().trim ().split (" " );
34
+
35
+ //input elements of array
36
+ for (int i =0 ; i <n ; i ++){
37
+ arr [i ]=Integer .parseInt (inputLine [i ]);
38
+ }
39
+
40
+ Mini obj = new Mini ();
41
+
42
+ System .out .println (obj .minAdjDiff (arr , n ));
43
+ }
44
+ }
45
+ }
You can’t perform that action at this time.
0 commit comments