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.

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

defflippingMatrix(matrix):# Write your code heresum_matrix=0nrows=len(matrix)forxinrange(nrows//2):foryinrange(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)returnsum_matrix

Cookie support is required to access HackerRank

Seems like cookies are disabled on this browser, please enable them to open this website

## Flipping the Matrix

You are viewing a single comment's thread. Return to all 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

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