-
Notifications
You must be signed in to change notification settings - Fork 0
/
Chef_And_Card_Trick.java
59 lines (59 loc) · 1.08 KB
/
Chef_And_Card_Trick.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
48
49
50
51
52
53
54
55
56
57
58
59
package rank;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Chef_And_Card_Trick
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader (System.in));
int t=Integer.parseInt(br.readLine());
while(t-->0)
{
long n=Long.parseLong(br.readLine());
int a[]=new int[(int) n];
for(long i=0;i<n;i++)
{
a[(int) i]=Integer.parseInt(br.readLine());
System.out.println(a[(int)i]);
}
int min=a[0];
long k=0;
for(long i=1;i<n;i++)
{
if(a[(int)i]<min)
{
min=a[(int)i];
k=i;
}
}
int c=0;
for(long i=k;i<n-1;i++)
{
if(a[(int)i]>a[(int)(i+1)])
{
System.out.println("NO");
c=1;
break;
}
}
if(c==0)
{
for(long i=0;i<k-1;i++)
{
if(a[(int)i]>a[(int)(i+1)])
{
System.out.println("NO");
c=1;
break;
}
}
}
if(c==0)
{
System.out.println("YES");
}
}
}
}