• + 0 comments

    No need to flip the matrix, each cell in the top quad will have only few possible options. For example, (0,0) can have (3,0), (0,3),(3,3) cells at its place when matrix is flipped. The formula for finding the possible cell values at this particular cell is

    length_of_matrix - 1 - idx
    

    All you have to do is, check max of all possible values at top quad for each cell. Top quad cells for 4x4 matrix is 00, 01, 10, 11 for 6x6, it will 00,01,02,10,11,12 and so on. below is the python solution that passes all tests

    def flippingMatrix(matrix):
        # Write your code here
        sum_matrix = 0
        nrows = len(matrix)
        for x in range(nrows//2):
            for y in range(nrows//2):
                possibilities = []
                possibilities.append(matrix[x][y])
                possibilities.append(matrix[nrows-1-x][y])
                possibilities.append(matrix[x][nrows-1-y])
                possibilities.append(matrix[nrows-1-x][nrows-1-y])
                sum_matrix += max(possibilities)
        return sum_matrix