• + 0 comments

    Solution from my side, i know that it is not well oprimized. but the logic of this solution is in the understandable format.

    def cavityMap(grid):
        data = []
        result = []
        indexData = []
    
        for item in grid:
            data.append(list(item))
    
        for i in range(1,len(data)-1):
            for j in range(1,len(data)-1):
                if(data[i][j+1]<data[i][j]> data[i][j-1] and data[i+1][j]<data[i][j]> data[i-1][j]):
                    indexData.append([i,j])
    
        for item01 in indexData:
            data[item01[0]][item01[1]] = 'X'
    
        for item03 in data:
            result.append(''.join(item03))
            
        return result