-
-
Notifications
You must be signed in to change notification settings - Fork 110
/
Copy pathGridChallenge.java
38 lines (35 loc) · 1.03 KB
/
GridChallenge.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
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for(int k=0;k<t;k++){
int n = sc.nextInt();
sc.nextLine();
char grid[][] = new char[n][n];
int a[][] = new int[n][n];
String output = "YES";
for(int i=0;i<n;i++){
grid[i] = sc.nextLine().toCharArray();
for(int j=0;j<n;j++){
a[i][j] = (int)(grid[i][j]);
}
Arrays.sort(a[i]);
}
for(int j=0;j<n;j++){
int temp = a[0][j];
for(int i=1;i<n;i++){
if(a[i][j]<temp)
output = "NO";
else
temp = a[i][j];
}
}
System.out.println(output);
}
}
}