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.

- Practice
- Mathematics
- Fundamentals
- Filling Jars
- Discussions

# Filling Jars

# Filling Jars

foulglory + 0 comments 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:

a,b,candy

do sumtotal = sumtotal + (b-a+1)x(candy) for each input

average = sumtotal/n

Hamada14 + 0 comments Someone Please Help :( All Test Cases are working except for #4 #5 #6

jjclxrk + 0 comments why even provide the boilerplate code if it is incompatible with the test cases?

victor_cooke + 0 comments My oneliner Python:

def solve(n, operations): return int(sum([(o[1]-o[0]+1)*o[2] for o in operations])/n)

Masters_Abh + 0 comments Sweet!

All the basic maths knowledge helps here!

No array means No timeouts.

Using long integers for avoiding overflows.

Reference: C++ Code

Load more conversations

Sort 160 Discussions, By:

Please Login in order to post a comment