• + 0 comments

    This is a simple Javascript solution with time complexity of O(n^2). This question is quite confusing so please watch this video to clearly understand the question and solution.

    function flippingMatrix(matrix) {
        const n =Math.floor(matrix.length / 2 );
        let arr = []; 
        for(let i = 0 ; i < n ; i++){
            for(let j = 0 ; j < n ; j++ ){
                let temp = [];
                
                temp.push( matrix[i][j] ); 
                temp.push( matrix[i][2*n-j-1] ) ; 
                temp.push( matrix[2*n-i-1][j] ) ; 
                temp.push( matrix[2*n-i-1][2*n-j-1] ) ; 
                arr.push(Math.max(...temp)) ; 
                
            }
        }
        
        let total = arr.reduce( (x,y) =>{
            return x + y ; 
        } ); 
        return total ; 
    }