diagonal difference hackerrank solution in java 8 using list

Solutions on MaxInterview for diagonal difference hackerrank solution in java 8 using list by the best coders in the world

showing results for - "diagonal difference hackerrank solution in java 8 using list"
Mattheo
28 Feb 2016
1prim =0
2    sec=0
3    length = len(arr[0])
4    for count in range(length):
5        prim += arr[count][count]
6        sec += arr[count][(length-count-1)]
7    return abs(prim-sec)
8    
Cleo
03 Jun 2019
1 public static int diagonalDifference(List<List<Integer>> arr) {
2    // Write your code here
3    int leftd=0;
4    int rightd=0;
5    int n=arr.size();
6    for(int i=0;i<n;i++)
7    {
8        leftd+=arr.get(i).get(i);
9        rightd+=arr.get(i).get(n-i-1);
10    }
11    int absd=Math.abs(leftd-rightd);
12    return absd;
13
14    }