Created
July 2, 2024 13:42
-
-
Save samarthsewlani/1c68a9abfe6f52992f35b7d29ea4b5da to your computer and use it in GitHub Desktop.
Diagonal Difference HackerRank Solution ( Python )
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
n = int(input()) | |
lst = [] | |
for i in range(n): | |
lst.append([int(x) for x in input().split()]) | |
a, b = 0, 0 | |
for i in range(n): | |
a += lst[i][i] | |
b += lst[i][n-i-1] | |
print(abs(a-b)) | |
""" | |
Alternate solution: | |
n = int(input()) | |
lst = [] | |
for i in range(n): | |
lst.append([int(x) for x in input().split()]) | |
a, b = 0, 0 | |
for i in range(n): | |
a += lst[i][i] | |
b += lst[i][-i-1] | |
print(abs(a-b)) | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment