## Samsung Interview Question

Developer Program Engineers Financial Software Developers**Team:**any

**Country:**United States

**Interview Type:**In-Person

This the the answer I gave it in interview and it worked for me... not sure if other interviewers will accept this solution.

Fill 3 Liter Jar

Pour it into 5 Liter jar

Fill 3 Liter Jar Again

Pour it into 5 Liter untll it's Full (Since it already had 3 Liter + 2 Liter jar will be full)

The 3 Liter will have exactly 1 Liter left.

Pour the 5 Liter Jar water out,

Put the water in 3 Liter to 5 Liter (Now 5 Liter jar will have 1 liter of water)

Now Fill 3 Liter water onto 3 Liter jar and put it onto 5 Liter jar.

The interviewer asked me, so, where are you getting the water from, since you are throwing away the water. I replied I am assuming we have a Tap source of water, since you did not mentioned it in the question.

The interviewer accepted it.

`one more solution is possible if the containers are perfectly cylindrical.Fill both containers to their full capacity and then tilt them till the water surface is aligned with its diagonal.Doing this will spill exactly half water from the container and exactly half will be left in both the containers.i.e., 5/2 = 2.5 and 3/2 = 1.5 which adds upto 4lts. In this way wastage of water will also be minimum.`

Assuming we can take another bucket to fill the measured quantity.

i. Fill the 3 litre bucket

ii. Pour the filled 3litre bucket to 5litre bucket ( Now 5litre bucket has 3 litres filled and 2 litres empty )

iii. Fill 3 litre bucket.

iv. Fill 5litre bucket with 3litre till it is full. ( Now 5 litre bucket is full and 3 litre bucket has 1 litre)

v. Pour 1litre of 3 litre bucket to new bucket.

vi. Fill 3 litre bucket and pour it into new bucket.

Finally we have 4 litres in new bucket

Hi,

Your 1st and 2nd solutions are actually good.

there is a general solution given 'a' sized bucket and 'b' sized bucket.

result (in litres ) = a * X + b * Y ( where X and Y are Integers )

Ex : a = 3, b = 5 result = 4

4 = 3 * (-2) + 5 (2)

In Words : in the whole process of getting 4 litres, we will fill 5 sized bucket 2 times and empty 3 sized bucket 2 times.

Hi Nikhil, I too faced the same question some times back with another organization but it was little different, in the sense, that, you can not use any extra bucket or jar, you have to do this with only 2 jars, one 5 ltr capacity and the other 3 ltr capacity with no labels or markings on the surface of the jars or bottles. I am also waiting if anybody can let me know that with only two jars how one can achieve the same that is 4 ltr as result.

tilt both of the buckets 45 degrees so when they are filled, it will only fill half of the bucket.

fill them as they are tilted, and 3 liter bucket will have 1.5 liter, and 5 liter bucket will have 2.5 liter.

pour the 1.5 liter in 3 liter bucket into 5liter bucket. Tadaa there is your 4 liter

(i) 5->3 = 2 liter

5->3 = 2 liter

(ii) 3->5->3->5 = 1 liter(Repeat this 4 times)

(iii) 3->5->3->5->1->5 = 4 liter

Please comment if this is not correct solution.

liked sharma answer

1.fill 5liter bucket pour it into 3lit bucket ,so now 2liters are left in 5litr bucket

2.empty 3litrs bucket and pour 5litrs water in 3litr bucket

3.fill 5liters bucket again and pour water in 3liter bucket until its full

left water in 5liter bucket will count to 4liters

{{Solution #1}}

1. fill the 5 ltr water and pour into 3 ltr bucket. (Now 5 ltr bucket have 2 Ltr reaining water)

2.Empthy 3 ltr ucket and pour it by 2 ltr remain in 5 ltr bucket. ( Now 5 ltr bucket empty and

3-ltr bucket is 2 ltr water filled.

3. Now fill the 5 ltr bucket and pour it into 3 ltr. (Now 5 ltr bucket exactly have 4 ltr water.)

hi guys......

first fill the 3 litre jar and pour the water into 5 litre jar

then again fill the 3 litre jar and again pour the water into 5 litre jar

now 5 litre jar is full and 3 litre jar have 1 litre water remaining then

empty the 5 litre jar and then pour that 1 litre water from 3 litre jar to 5 litre jar.

now 5 litre jar have 1 litre water and 3 litre jar is empty..after that fill 3 litre jar and pour the water into 5 litre jar

now 5litre jar have 4 litre water.....that sit...

1) hold 3L1 bucket over 5L1 bucket. Use another 5L2 bucket and empty it over 3L1, repeat it 2 times. The water in 5L1 bucket will be 4 liters.

2) hold 5L1 bucket over 5L2 bucket. Use a 3L bucket and 9 time pour water in 5L1. The water in 5L2 bucket will be 4 liters.

2) Fill 5L1 and 5L2 then fill 3L1 and 3L2 from these 5L buckets. Finally, put water of both 5L buckets in one which will be 4 liters.

Step 1: Fully fill the 5L jar and then use this filled one to completely fill 3L jar. Once 3L jar is filled, you have 2L water in 5L jar left. Now, empty 3L jar and transfer the water from 5L into 3L.

Again fill the 5L jar and then transer water from this to #l jar until full. The remaining water in 5L jar that will remain is 4L.

Step 1: Fully fill the 5L jar and then use this filled one to completely fill 3L jar. Once 3L jar is filled, you have 2L water in 5L jar left. Now, empty 3L jar and transfer the water from 5L into 3L.

Step 2Again fill the 5L jar and then transer water from this to 3L jar until full. The remaining water in 5L jar that will remain is 4L.

I can think of 3 solutions:

1st:- (using 3ltr jar, total water used = 9lts)

fill 3lts jar add to 5lts one fill and other add to 5lts on 1ltr will be left in 3lts jar.remove

water from 5lts jar and put the 1lts left in 3lts jar to it.Now again fill 3lts jar add to 5lts

and u have 4lts.

2nd:-(using 5lts jar, total water required = 10lts)

fill 5ltr jar and fill 3lts jar from it.empty the 3ltr jar .transfer remaining 2ltr from 5ltr jar

3ltr jar fill 5ltr jar again add 1ltr water to 3ltr jar and their u have 4 ltr water in 5ltr jar.

3rd:-(assuming both jar are perfectly cylindrical, total water required = 8lts)

fill both the jar. Now tilt them till the water surface align with the diagonal perfectly.

Doing this will spill exactly half the amount of water out leaving exactly half water in

jars which adds upto 4 ltrs.

there is one more way .. fill 3ltr jar with 5ltr jar ... now 2ltr left in 5ltr jar .. empty 3ltr jar and fill it with the liquid left in 5ltr jar .. now 5ltr jar is empty .. fill it again and completely fill the 3ltr jar ie. the 1ltr left in it ... so now 5ltr jar contain 4ltr ..

- mAn1Ac March 25, 2013