You are viewing a single comment's thread. Return to all comments →
public static int diagonalDifference(List> arr) { // Write your code here
int primaryDiagnolSum =0; int secondaryDiagnolSum =0;
for(int i=1; i<=arr.size();i++) { List intArray = arr.get(i-1); primaryDiagnolSum+=intArray.get(i-1); secondaryDiagnolSum+= intArray.get(arr.size()-i);
}
int difference = primaryDiagnolSum-secondaryDiagnolSum; return (difference<0)?difference*-1: difference;
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 →
public static int diagonalDifference(List> arr) { // Write your code here
for(int i=1; i<=arr.size();i++) { List intArray = arr.get(i-1); primaryDiagnolSum+=intArray.get(i-1); secondaryDiagnolSum+= intArray.get(arr.size()-i);
}
int difference = primaryDiagnolSum-secondaryDiagnolSum; return (difference<0)?difference*-1: difference;