Skip to content

Instantly share code, notes, and snippets.

@samarthsewlani
Created July 2, 2024 13:42
Show Gist options
  • Save samarthsewlani/1c68a9abfe6f52992f35b7d29ea4b5da to your computer and use it in GitHub Desktop.
Save samarthsewlani/1c68a9abfe6f52992f35b7d29ea4b5da to your computer and use it in GitHub Desktop.
Diagonal Difference HackerRank Solution ( Python )
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