Diagonal Difference

  • + 0 comments

    Extremely slow but easy to understand for newbies

    `public static int diagonalDifference(List> arr){ // Write your code here int ans = 0; int left_sum = 0; int right_sum = 0; //left_sum - first for(int i = 0; i < arr.size(); i++){ for(int j = i ; j < arr.get(i).size(); j++){ left_sum += arr.get(i).get(j); break; } } for(int i = 0; i < arr.size(); i++){ for(int j = arr.get(i).size()-1 - i ; j >= arr.get(i).size()-1-i; j--){ right_sum += arr.get(i).get(j); break; } } return Math.abs(left_sum - right_sum); }
    }

    `