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)

## 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.

Some problems are so simple that running time doesn't matter and writing short and concise code is more challenging and more fun, that's it.

In big O notation the 3 drops off and becomes O(n) we only care when it goes from O(n) to say O(n^2) or even worse O(x^n).

A variation of this using the cmp built-in function

very efficient!