-
Notifications
You must be signed in to change notification settings - Fork 0
/
DS_max_index.java
47 lines (45 loc) · 928 Bytes
/
DS_max_index.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
import java.util.*;
import java.lang.*;
import java.io.*;
class DS_max_index.java {
public static void main (String[] args) {
//code
Scanner scan =new Scanner(System.in);
int t,n;
t=scan.nextInt();
while(t-->0)
{
n=scan.nextInt();
long a[]=new long[n];
for(int i=0;i<n;i++)
a[i]=scan.nextInt();
System.out.println(maxindex(a,n));
}
}
static int maxindex(long a[],int n)
{
int j=n-1,i=n,count=0,p=0;
while(i>0)
{
count=p;
int flag=-1;
while(count>=0)
{
if(a[j]>=a[count])
{
return j-count;
// flag=1;
}
else
{
j--;
count--;
}
}
p++;
j=n-1;
i--;
}
return -1;
}
}