Calculate the absolute difference between the sums of its diagonals.(Hacker Rank Problem )




Diagonal Difference





Solution 


public static int diagonalDifference(List<List<int>> arr) { int d1=0,d2=0; int count=arr.Count; for(int i=0;i<=arr.Count-1;i++) { for(int j=0;j<=arr[i].Count-1;j++) { if(i==j) { d1+=arr[i][j]; } if(i==count-j-1) { d2+=arr[i][j]; } } } return Math.Abs(d1-d2); }
Share:

No comments:

Post a Comment

Popular

Tags

Mobile

Recent Posts