CHALLENGE : Bucket Problem | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 9

CHALLENGE : Bucket Problem

There are infinite no of buckets and N no of water. This bucket have a unique property . The capacity of ith bucket is ith liters i.e.capacity of 1st bucket is 1 liter the capacity of 2nd bucket is 2 liters. Also the ith bucket can only be filled when all the buckets which have lesser capacity are totally filled i.e 2nd bucket can not be filled before 1st bucket. take the amount of water as input and find the no of buckets to be filled by the amount of water.

25th Feb 2018, 5:56 PM
Tanay
Tanay - avatar
4 Answers
+ 17
1-liner method //2.5 lites will fill 1.75 bucket(s) @Nomeh ☺ https://code.sololearn.com/cAYxf3Egtmw4/?ref=app
25th Feb 2018, 7:03 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
25th Feb 2018, 7:23 PM
Tanay
Tanay - avatar
+ 4
could I say that 2.5ltrs of water can fill 1 bucket or 2 buckets?
25th Feb 2018, 6:07 PM
Nomeh Uchenna Gabriel
Nomeh Uchenna Gabriel - avatar
+ 4
I overly complicated the whole thing, I think, but I wanted to play with classes, so there it is. https://code.sololearn.com/cuoQtj9N1U8J/#py
26th Feb 2018, 5:57 AM
Pedro Demingos
Pedro Demingos - avatar