function convertToArray(grid){
for(let i=0;i<grid.length;i++){
grid[i] = grid[i].split('');
}
return grid;
}
function gridChallenge(grid) {
// if grid is 1x1 then just return YES
if(grid.length==1){
return 'YES'
}
grid = convertToArray(grid);
//sort grid
for(let i=0;i<grid.length;i++){
grid[i].sort();
}
//compare verticaly
let x=0;
let y=0;
while(y < grid[0].length){
if(x==grid.length-1){
x=0;
y++;
}
if(grid[x][y]>grid[x+1][y]){
return 'NO'
}
x++;
}
return 'YES';
}