Grid Challenge Discussions | | HackerRank

Grid Challenge

  • + 0 comments

    Here is one way to do it in javaScript

    function gridChallenge(grid) {
        // Write your code here
        const sortedGrid = grid.map(row => row.split('').sort().join(''))
    
        for(let col = 0; col < sortedGrid[0].length; col++){
            for(let row = 1; row < sortedGrid.length; row++){
                if(sortedGrid[row][col] < sortedGrid[row - 1][col]){
                    return "NO"
                }
            }
        }
    
        return "YES"
    }