Diagonal Difference

  • + 0 comments

    JAVA code public static int diagonalDifference(List> arr) { // Write your code here int primaryDiagonalSum = 0; int secondaryDiagonalSum = 0;

    for (int i = 0; i < arr.size(); i++) {
        primaryDiagonalSum += arr.get(i).get(i);
        secondaryDiagonalSum += arr.get(i).get(arr.size() - i - 1);
    }
    
    int diff = Math.abs(primaryDiagonalSum - secondaryDiagonalSum);
    return diff;
    }