-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathgridChallenge.js
More file actions
68 lines (58 loc) · 1.46 KB
/
gridChallenge.js
File metadata and controls
68 lines (58 loc) · 1.46 KB
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
60
61
62
63
64
65
66
67
68
function processData(r,sortedArr) {
if(r==1){
return "YES";
}
var arr=[];
//sorting row-wise
for(var i=0; i<r; i++){
for(var j=0; j<r; j++){
arr.push(sortedArr[i][j]);
}
arr.sort();
for(var col=0; col<r; col++){
sortedArr[i][col]= arr[col];
}
arr=[];
}
for(var i=0; i<r; i++){
for(var j=0; j<r; j++){
arr.push(sortedArr[j][i]);
}
arr.sort();
for(var row=0; row<r; row++){
if(sortedArr[row][i]!= arr[row]){
return "NO";
}
}
arr=[];
}
return "YES";
}
function main() {
var t= parseInt(readLine());
for(var i=0; i<t; i++){
var row=0;
var r= parseInt(readLine());
if(r==1){
var s = readLine();
var result=processData(r,s);
console.log(result);
}
else{
var arrMatrix=new Array(r);
for(var k=0; k<r; k++){
arrMatrix[k]= new Array(r);
}
while(row<r){
var s = readLine();
var strArr= s.split("");
for(var col=0; col<r; col++){
arrMatrix[row][col]=strArr[col];
}
row++;
}
var result=processData(r,arrMatrix);
console.log(result);
}
}
}