Sort 160 Discussions, By:
Please Login in order to post a comment
If you're getting timeout:
The whole thing can actually be solved in one loop. Initialize sumtotal to 0. Run the loop m times/while input exists whatever you choose, take input one by one in list/array whatever you use.
Input is of the form:
do sumtotal = sumtotal + (b-a+1)x(candy)
for each input
average = sumtotal/n
Someone Please Help :(
All Test Cases are working except for #4 #5 #6
why even provide the boilerplate code if it is incompatible with the test cases?
My oneliner Python:
def solve(n, operations):
return int(sum([(o-o+1)*o for o in operations])/n)
All the basic maths knowledge helps here!
No array means No timeouts.
Using long integers for avoiding overflows.
Reference: C++ Code