• + 0 comments

    Java 8

    public static int flippingMatrix(List<List<Integer>> matrix) {
            int result = 0;
            int halfMatrixSize = matrix.size() / 2;
            int maxMatrixIndex = matrix.size() - 1;
                
            for (int row = 0; row < halfMatrixSize; row ++) {
                for (int col = 0; col < halfMatrixSize; col ++) {
                    int element = matrix.get(row).get(col);
                    int rightMirror = matrix.get(row).get(maxMatrixIndex - col);
                    int downMirror = matrix.get(maxMatrixIndex - row).get(col);
                    int rightDownMirror = matrix.get(maxMatrixIndex - row)
                    .get(maxMatrixIndex - col);
                    
                    result += Arrays.asList(element, rightMirror, downMirror, rightDownMirror)
                    .stream().max(Integer::compare).get();
                }
            }
            return result;
        }