Diagonal Difference

  • + 0 comments

    Java Solution:

        public static int diagonalDifference(List<List<Integer>> arr) {
    
            int leftSum = 0;
            int rightSum = 0;
            
            for(int i=0; i<arr.size();i++){
                List<Integer> row = arr.get(i);
                leftSum = leftSum + row.get(i);
                rightSum = rightSum + row.get(row.size() -1  - i);
            }
            
            return leftSum > rightSum ? (leftSum - rightSum) : (rightSum - leftSum);
        }