Skip to content

Commit

Permalink
adding more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
codeperfectplus committed Oct 4, 2021
1 parent 5cbcbe0 commit b616ac6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 37 deletions.
26 changes: 4 additions & 22 deletions 05. DiagonalDifference/solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@
Url : https://www.hackerrank.com/challenges/diagonal-difference/problem
'''
#!/bin/python3

import math
import os
import random
import re
import sys

#
# Complete the 'diagonalDifference' function below.
#
# The function is expected to return an INTEGER.
Expand All @@ -22,22 +14,12 @@

def diagonalDifference(arr):
# Write your code here
n = len(arr)
d1 = sum(arr[i][i] for i in range(n))
d2 = sum(arr[i][n-i-1] for i in range(n))
return abs(d1 - d2)

if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')

n = int(input().strip())

arr = []

for _ in range(n):
arr.append(list(map(int, input().rstrip().split())))

result = diagonalDifference(arr)

fptr.write(str(result) + '\n')

fptr.close()
assert diagonalDifference([[11,2,4], [4,5,6], [10,8,-12]]) == 15
assert diagonalDifference([[1,2,3], [4,5,6], [9,8,9]]) == 2
assert diagonalDifference([[1,1,1,1], [1,1,1,1], [1,1,1,1], [1,1,1,1]]) == 0
20 changes: 5 additions & 15 deletions 06. PlusMinus/solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,19 @@
'''
#!/bin/python3

import math
import os
import random
import re
import sys

# Complete the plusMinus function below.
def plusMinus(arr):
countPositive = 0
countNegative =0
n = len(arr)
for i in range(n):
if arr[i] > 0:
countPositive += 1
elif arr[i] < 0:
countNegative += 1
countZero = n - countPositive-countNegative
print(countPositive/n)
print(countNegative/n)
print(countZero/n)
print("Count Positive:", countPositive/n)
print("Count Negative:", countNegative/n)
print("Count Zero:", countZero/n)

if __name__ == '__main__':
n = int(input())

arr = list(map(int, input().rstrip().split()))

plusMinus(arr)
plusMinus([-4, 3, -9, 0, 4, 1])

0 comments on commit b616ac6

Please sign in to comment.