You are viewing a single comment's thread. Return to all comments →
Javascript solution:
function cavityMap(grid) { for (let i = 1; i < grid.length - 1; i++) { let str = grid[i].split(""); for (let j = 1; j < str.length - 1; j++) { if ( [str[j - 1], str[j + 1], grid[i - 1][j], grid[i + 1][j]].every( (val) => str[j] > val ) ) { str[j] = "X"; } } grid[i] = str.join(""); } return grid; }
Seems like cookies are disabled on this browser, please enable them to open this website
Cavity Map
You are viewing a single comment's thread. Return to all comments →
Javascript solution: