• + 1 comment

    Solution with explanation in Python 3:

    def flippingMatrix(matrix: list[list[int]]) -> int:
        """
        Since any number of column/row flips are possible,
        The maximum values must come from rotations around the center.
        Also, since the problem doesn't require the resultant matrix,
        we can simply determine the largest values for each position
        then return their sum.
        
        q=4
        n=q/2
        m=[
          [ 1, 2, 3, 4],
          [ 5, 6, 7, 8],
          [ 9,10,11,12],
          [13,14,15,16],
        ]
        Top left quad must consist of max for each rotation:
        0,0:max([1,4,13,16]) 0,1:max([2,3,14,15])
        1,0:max([5,8,9,12])  1,1:max([6,7,10,11])
        
        Generalized, these can be represented as follows:
        r,c: max([m[r][c], m[r][q-1-c], m[q-1-r][c], m[q-1-r][q-1-c]])
        
        find the max value for each r,c set
        return the sum of max values
        """
        
        q = len(matrix)
        n = q//2
        m = matrix
        
        # get quad value arrays
        quad_values = [
            [
                max([m[r][c], m[r][q-1-c], m[q-1-r][c], m[q-1-r][q-1-c]])
                for c in range(n)
            ]
            for r in range(n)
        ]
        print(quad_values)
        return sum([sum([c for c in r]) for r in quad_values])