Answers for "diagonal difference hackerrank solution python"

0

diagonal difference hackerrank solution in java 8 using list

public static int diagonalDifference(List<List<Integer>> arr) {
    // Write your code here
    int leftd=0;
    int rightd=0;
    int n=arr.size();
    for(int i=0;i<n;i++)
    {
        leftd+=arr.get(i).get(i);
        rightd+=arr.get(i).get(n-i-1);
    }
    int absd=Math.abs(leftd-rightd);
    return absd;

    }
Posted by: Guest on July-04-2020
0

diagonal difference hackerrank solution in python

def diagonalDifference(arr):
    # Write your code here
    d1 = sum([arr[x][x] for x in range(len(arr))])
    d2 = sum([arr[x][n - 1 - x] for x in range(len(arr))])
    return(abs(d1 - d2))
Posted by: Guest on March-24-2021

Code answers related to "diagonal difference hackerrank solution python"

Python Answers by Framework

Browse Popular Code Answers by Language