Simple | BRUTE | OPTIMAL Approach in JAVA
Code\n\n<!-- Brute Approach -->\nclass Solution {\n    public int diagonalSum(int[][] mat) {\n        int sum=0;\n     for(int i=0;i<mat.length;i++)\n     {\n  
# Code\n```\n<!-- Brute Approach -->\nclass Solution {\n    public int diagonalSum(int[][] mat) {\n        int sum=0;\n     for(int i=0;i<mat.length;i++)\n     {\n         for(int j=0;j<mat[i].length;j++)\n         {\n             if(i==j){\n                 sum=sum+mat[i][j];\n             }else if(i+j==mat.length-1){\n                 sum=sum+mat[i][j];\n             }\n         }\n     }        \n     return sum; \n    }\n}\n\n```\n```\n<!-- Optimal Approach -->\nclass Solution {\n    public int diagonalSum(int[][] mat) {\n        int sum=0;\n         \n        for(int i=0;i<mat.length;i++)\n        {\n            sum+=mat[i][i];\n\n            if(i!=mat.length-i-1)\n            {\n                sum+=mat[i][mat.length-i-1];\n            }\n        }       \n     return sum; \n    }\n}\n\n
['Array', 'Java']