We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
no need to two variables to calculate result.
In Java
public static int diagonalDifference(List> arr) {
int n = arr.size();
int result =0;
for (int i = 0; i < n; i++) {
result += arr.get(i).get(i) - arr.get( i).get(n - i -1);
}
return Math.abs(result);
}
Cookie support is required to access HackerRank
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 →
no need to two variables to calculate result. In Java public static int diagonalDifference(List> arr) { int n = arr.size(); int result =0; for (int i = 0; i < n; i++) { result += arr.get(i).get(i) - arr.get( i).get(n - i -1); } return Math.abs(result); }