We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
In this above solution the run time is O(3n) and we could make this as O(n) by using the dict to track the count of integers like positive, negative and zero values.
size_of_list = int(input())
list_of_int = map(int, raw_input().split(" "))
count_of_deci = {"posi" : 0,
"neg" : 0,
"zero" : 0}
for ele in list_of_int:
if ele < 0:
count_of_deci["neg"] += 1
elif ele == 0:
count_of_deci["zero"] += 1
elif ele > 0:
count_of_deci["posi"] += 1
print "%.3f" % float(float(count_of_deci["posi"])/size_of_list)
print "%.3f" % float(float(count_of_deci["neg"])/size_of_list)
print "%.3f" % float(float(count_of_deci["zero"])/size_of_list)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Plus Minus
You are viewing a single comment's thread. Return to all comments →
In this above solution the run time is O(3n) and we could make this as O(n) by using the dict to track the count of integers like positive, negative and zero values.