-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGrid_Challenge.java
More file actions
48 lines (48 loc) · 815 Bytes
/
Grid_Challenge.java
File metadata and controls
48 lines (48 loc) · 815 Bytes
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
package practicetime;
import java.util.*;
public class Grid_Challenge
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
for(int t1=0;t1<t;t1++)
{
int n=sc.nextInt();
String s[]=new String[n];
String s1[]=new String[n];
for(int i=0;i<n;i++)
{
s[i]=sc.next();
}
for(int i=0;i<n;i++)
{
char tmp[]=s[i].toCharArray();
Arrays.sort(tmp);
s1[i]=new String(tmp);
}
int ct=1,j;
for(int i=0;i<n;i++)
{
for(j=0;j<n-1;j++)
{
if(s1[j].charAt(i)>s1[j+1].charAt(i))
{
System.out.println("NO");
ct=0;
break;
}
}
if(ct==0)
{
break;
}
}
if(ct==1)
{
System.out.println("YES");
}
ct=1;
}
}
}