• + 5 comments

    An incredibly easy problem, once you make the observation that you don't actually have to reverse the matrix. I didn't really understand this, so I sketched out possibilities and made a nice diagram of possibilities:

    An implementation of this in Python3 is below. The tilde for an integer i is equivalent to -i-1, which fetches the mirror opposite value, making it very useful i/r/t its problem. I didn't spot any other solutions using it though.

    def flippingMatrix(matrix):
        sum = 0
        
        for i in range(n):
            for j in range(n):
                sum += max(matrix[i][j], matrix[i][~j], matrix[~i][j], matrix[~i][~j])
        
        return sum