• + 1 comment

    Symmetry: We exploit the symmetry of the 2Nx2N matrix to reduce calculations. Maximum value: For each position inside N x N, we find the maximum among the number and its three symmetric counterparts. Summation: The sum of these maximum values gives us the desired result.

        public static int flippingMatrix(List<List<Integer>> matrix) {
            int n = matrix.get(0).size()/2;
            int result = 0; 
            for(int i = 0; i<n; i++) {
                for(int j = 0; j<n; j++){
                    result += Math.max(matrix.get(i).get(j), Math.max(matrix.get(2*n-1-i).get(j),
                    Math.max(matrix.get(2*n-1-i).get(2*n-1-j), matrix.get(i).get(2*n-1-j))));
                }
            }
            return result;
        }