We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
The one gotcha here is that the prompt is incorrect: a SQUARE grid is not guaranteed.
Order the rows as requested, then check "vertically" for top-down ascending order of columns as well.
While this approach is fairly brute-force, it returns as soon as it finds the current row to be "greater than" the row below it.
functiongridChallenge(grid){// Should order each row in a one-linerconstordered=grid.map((row)=>row.split('').sort().join(''));console.log(ordered);// operate on row-levelfor(leti=0;i<grid.length-1;i++){// column levelfor(letj=0;j<grid[0].length;j++){letcur=ordered[i][j];letnext=ordered[i+1][j];if(cur>next){return"NO";}}}return"YES";}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Grid Challenge
You are viewing a single comment's thread. Return to all comments →
[javascript]
The one gotcha here is that the prompt is incorrect: a SQUARE grid is not guaranteed.
Order the rows as requested, then check "vertically" for top-down ascending order of columns as well.
While this approach is fairly brute-force, it returns as soon as it finds the current row to be "greater than" the row below it.