Diagonal Difference

  • + 0 comments

    int rightDiagonal = 0; int secondaryDiagonal = 0;

        int n = arr.size();
    
        for (int i = 0; i < n; i++) {
            rightDiagonal += arr.get(i).get(i);
            secondaryDiagonal += arr.get(i).get(n - i - 1);
        }
    
        return Math.abs(rightDiagonal - secondaryDiagonal);