You are viewing a single comment's thread. Return to all 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; }
Seems like cookies are disabled on this browser, please enable them to open this website
Diagonal Difference
You are viewing a single comment's thread. Return to all comments →
JAVA code public static int diagonalDifference(List> arr) { // Write your code here int primaryDiagonalSum = 0; int secondaryDiagonalSum = 0;