Skip to content

Commit 5839472

Browse files
committed
issue sowon-dev#28 Grid Challenge java
1 parent ecf79f7 commit 5839472

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

‎src/hackerrank/GridChallenge.java‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package hackerrank;
2+
3+
import java.util.Arrays;
4+
5+
public class GridChallenge {
6+
static String gridChallenge(String[] grid) {
7+
char ll[] = new char[grid.length];
8+
char b[] = new char[grid.length];
9+
boolean xx=true;
10+
int i=0;
11+
while(xx && i<grid[0].length()){
12+
for(int j=0 ; j<grid.length;j++ ){
13+
ll[j]=grid[j].charAt(i);
14+
}
15+
16+
b= Arrays.copyOf(ll,grid.length);
17+
Arrays.sort(ll);
18+
19+
if(!(Arrays.equals(b,ll))){
20+
xx=false;
21+
break;
22+
}
23+
i++;
24+
}
25+
26+
if(xx){
27+
return "YES";
28+
}
29+
else{
30+
return "NO";
31+
}
32+
}
33+
34+
public static void main(String[] args) {
35+
System.out.println(gridChallenge(new String[]{"abc", "ade", "efg"})+", ans:YES");
36+
System.out.println(gridChallenge(new String[]{"ebacd", "fghij", "olmkn", "trpqs", "xywuv"})+", ans:YES");
37+
}
38+
}

0 commit comments

Comments
 (0)