-
Notifications
You must be signed in to change notification settings - Fork 2
/
Greater_Than_Neighbour.java
47 lines (44 loc) · 1.3 KB
/
Greater_Than_Neighbour.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package com.company;
import java.io.IOException;
import java.util.Scanner;
public class Greater_Than_Neighbour {
public static void main(String[] args) throws IOException {
Scanner s = new Scanner(System.in);
int t = s.nextInt();
while (t != 0) {
int n = s.nextInt();
int[] arr = new int[1000];
for (int i = 0; i < n; i++) {
arr[i] = s.nextInt();
}
neighbour(arr);
t--;
}
}
private static void neighbour(int[] arr) {
int count = 0;
int[] arrayList = new int[arr.length];
for (int i = 0; i < arr.length; i++) {
if (i == 0) {
if (arr[i] > arr[i + 1]) {
System.out.print(i+" ");
count++;
}
} else if (i == arr.length - 1) {
if (arr[i] > arr[arr.length - 1]) {
System.out.print(i+" ");
count++;
}
} else {
if (arr[i] > arr[i - 1] && arr[i] > arr[i + 1]) {
System.out.print(i+" ");
count++;
}
}
}
if(count == 0){
System.out.println(-1);
}
System.out.println();
}
}