• + 0 comments

    Python 3

    It took me a couple of hours to understand which elements of the matrix need to be summed in order to compute to the max sum, I still do not understand why this pattern applies? How could I have recoginised this symmetry?

    [ ['A', 'B', 'B', 'A'], ['C', 'D', 'D', 'C'], ['C', 'D', 'D', 'C'], ['A', 'B', 'B', 'A'] ]

    `def flippingMatrix(matrix): n = len(matrix) // 2 max_sum = 0

    for row in range(n):
        for col in range(n):
            top_left = matrix[row][col]
            top_right = matrix[row][2*n - 1 - col]
            bottom_left = matrix[2*n - 1 - row][col]
            bottom_right = matrix[2*n - 1 - row][2*n - 1 - col]
    
            max_value =  max(top_left, top_right, bottom_left, bottom_right)
            max_sum += max_value
    
    return max_sum