Instantly share code, notes, and snippets.

# Goddard/diagonalDifference.py

Created April 15, 2019 13:38
something I did for hankerrank
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
 #!/bin/python3 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') fptr.close()