Diagonal Difference

  • + 0 comments

    My submission is Below: Please give inputs about the approach

     public static int diagonalDifference(List<List<Integer>> arr) {
        // Write your code here
        int countp=0,counts =0;
            for(int i=0,j=arr.size()-1;i<arr.size()&&j>=0;i++,j--){
                countp = countp + arr.get(i).get(i);
                counts= counts + arr.get(i).get(j);
            }
            if(countp<=counts){
                return counts-countp;
            }else{
                return countp-counts;
            }
        }