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.
Isolated the inner grid and then checked with neighbors with inplace replacement in string
defcavityMap(grid):n_row=len(grid)n_col=len(grid[0])result=grid[:]# Define the range for the inner gridmr=range(1,n_row-1)mc=range(1,n_col-1)forrowinmr:forcolinmc:# Check all neighborsif(grid[row][col]>grid[row][col+1]andgrid[row][col]>grid[row][col-1]andgrid[row][col]>grid[row-1][col]andgrid[row][col]>grid[row+1][col]):# Modify the result gridresult[row]=result[row][:col]+"X"+result[row][col+1:]returnresult
Cookie support is required to access HackerRank
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 →
Python 3
Isolated the inner grid and then checked with neighbors with inplace replacement in string