Grid Challenge Discussions | | HackerRank

Grid Challenge

  • + 0 comments

    JS/Javascript Solution, with 3 loops! Any improvement suggestions?

    function gridChallenge(grid) {
        const orderedArr = grid.map(row => row.split('').sort().join(''));
        for (let i = 0;i< grid.length;i++) {
            for (let j = 0;j< grid.length - 1;j++) {
                if (orderedArr[j][i] > orderedArr[j+1][i]) {
                    return "NO";
                }
            }
        }
        return 'YES';
    }