Skip to content

Commit 0daa5c3

Browse files
Merge pull request seeditsolution#250 from cadwellh5/patch-3
Diagonal Difference of an array
2 parents 13dc02d + a56051d commit 0daa5c3

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

diagonaldifference

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
def diagonalDifference(arr) #function accepting a 2d array
2+
3+
sum1=0
4+
sum2=0
5+
res=0
6+
for i in range(0,len(arr)):
7+
sum1=sum1+arr[i][i]
8+
sum2=sum2+arr[i][(len(arr)-1)-i]
9+
res=sum1-sum2
10+
return abs(res)
11+
if __name__ == '__main__':
12+
fptr = open(os.environ['OUTPUT_PATH'], 'w')
13+
14+
n = int(input().strip) #size
15+
16+
arr = []
17+
18+
for _ in range(n):
19+
arr.append(list(map(int, input().rstrip().split())))
20+
21+
print( diagonalDifference(arr))
22+

0 commit comments

Comments
 (0)