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.
defcavityMap(grid):# Write your code herecavity=grid.copy()#overwritingoriginalgridwouldcauseerrorforiinrange(1,len(grid)-1):#iteratethrueachrowignorefirstandlastcur=grid[i]pre=grid[i-1]nex=grid[i+1]forjinrange(1,len(cur)-1):#identifycellanditsadjacenciescell=cur[j]left=cur[j-1]rght=cur[j+1]topp=pre[j]botm=nex[j]ifcell>leftandcell>rghtandcell>toppandcell>botm:cavity[i]=cavity[i][:j]+'X'+cavity[i][j+1:]returncavity
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 →
my python approach, aiming for legibility mostly.