Skip to content

Instantly share code, notes, and snippets.

@mllopart
Created June 16, 2017 14:29
Show Gist options
  • Save mllopart/58a945418ae49308a2ed79b32dc956fd to your computer and use it in GitHub Desktop.
Save mllopart/58a945418ae49308a2ed79b32dc956fd to your computer and use it in GitHub Desktop.
Diagonal Difference - Hackerrank test
#!/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