Skip to content

Commit f6bb7ef

Browse files
author
asundaresan
committed
grid challenge submission
1 parent ba59c25 commit f6bb7ef

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

Greedy/Grid Challenge/Aravind.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import java.io.*;
2+
import java.util.*;
3+
import java.text.*;
4+
import java.math.*;
5+
import java.util.regex.*;
6+
7+
public class Solution {
8+
9+
public static void main(String[] args) {
10+
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
11+
Scanner scan = new Scanner(System.in);
12+
int count = scan.nextInt();
13+
for(int i = 0; i < count; i++) {
14+
int N = scan.nextInt();
15+
char[][] G = new char[N][N];
16+
for(int j = 0; j < N; j++) {
17+
String line = scan.next();
18+
for(int k = 0; k < N; k++) {
19+
G[j][k] = line.charAt(k);
20+
}
21+
Arrays.sort(G[j]);
22+
}
23+
boolean possible = true;
24+
for(int j = 0; j < N && possible; j++) {
25+
for(int k = 1; k < N && possible; k++) {
26+
if(Character.compare(G[k][j], G[k-1][j]) < 0) possible = false;
27+
}
28+
}
29+
System.out.println(possible ? "YES" : "NO");
30+
}
31+
}
32+
}

0 commit comments

Comments
 (0)