Skip to content

Instantly share code, notes, and snippets.

@codeperfectplus
Created September 13, 2023 03:47
Show Gist options
  • Save codeperfectplus/bb403ba374ca5fc183a15577fd57361d to your computer and use it in GitHub Desktop.
Save codeperfectplus/bb403ba374ca5fc183a15577fd57361d to your computer and use it in GitHub Desktop.
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)
def test_case_0():
arr = [-4, 3, -9, 0, 4, 1]
plusMinus(arr)
test_case_0()
# output
# 0.5
# 0.3333333333333333
# 0.16666666666666666
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment