Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
something I did for hankerrank
import math
import os
import random
import re
import sys
# Complete the diagonalDifference function below.
def diagonalDifference(arr):
largest_row = 0
result1 = 0
result2 = 0
for x, row in enumerate(arr):
if(largest_row < len(row)):
largest_row = len(row)
for x in range(largest_row):
for y in range(largest_row):
if(y > len(arr[x])):
arr[x][y] = 0
count = 0
for x in range(len(arr)):
result1 += arr[x][count]
count += 1
count = len(arr)-1
for x in range(len(arr)):
result2 += arr[x][count]
count -= 1
return abs(result1 - result2)
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
n = int(input())
arr = []
for _ in range(n):
arr.append(list(map(int, input().rstrip().split())))
result = diagonalDifference(arr)
fptr.write(str(result) + '\n')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.