• + 1 comment

    In my perspective, it's akin to solving a Rubik's Cube. The key is identifying which numbers are viable choices for each target position, and then select the highest among them to place in that position.

    Here is the Javascript version

    function flippingMatrix(matrix) {
        // Write your code here
        const di = matrix.length/2
        const l = matrix.length-1
        const result = []
        
        for(let j = 0; j < di; j++){
            for(let i = 0; i < di; i++){
                const query = Math.max(matrix[j][i],matrix[j][l-i],matrix[l-j][i],matrix[l-j][l-i])
                result.push(query)
            }
        }
        return result.reduce((pre,cur)=>pre+cur,0);
    }