Diagonal Difference

  • + 0 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;

    }