Created
June 16, 2017 14:29
-
-
Save mllopart/58a945418ae49308a2ed79b32dc956fd to your computer and use it in GitHub Desktop.
Diagonal Difference - Hackerrank test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/python3 | |
#Given a square matrix of size NxN , calculate the absolute difference between the sums of its diagonals. | |
import sys | |
n = int(input().strip()) | |
a = [] | |
for a_i in range(n): | |
a_t = [int(a_temp) for a_temp in input().strip().split(' ')] | |
a.append(a_t) | |
sum_first_diagonal = sum(a[i][i] for i in range(n)) | |
sum_second_diagonal = sum(a[i][n-i-1] for i in range(n)) | |
print(str(abs(sum_first_diagonal-sum_second_diagonal))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment