Amazon Interview Question
Quality Assurance EngineersTeam: Kindle
Country: India
Interview Type: In-Person
The sequences
0 3 6.5
3 3 3.5
&
0 1 3.5 (5L waste)
1 3 0.5
actually consists of 3 steps each. Wastage is more(5L) than in my case(1.5L)
In SIX Steps with No Water Wastage..
Initially.. 0,0,9.5
step1: 5,0,4.5
step2: 2,3,4.5
step3: 2,0,7.5
step4: 0,2,7.5
step5: 5,2,2.5
step6: 4,3,2.5
@mrudal does this solution feasible one??? the question says minimal water wastage and minimal steps ...
@Rashmi....i think according to question it's not compulsory to waste the water....and the question says minimum water wastage so i minimized the wastage of water upto atleast level....
there was one more condition that once you taken out water from the pool you can not put back.
From the problem statement, wastage can only happen if the user is allowed to use two jars only.
According to that assumption, I could think of following solution;
Fill the ---
5L 0
2L 3L
2L 0 (3L wastage)
0 2L
5L 2L
4L 3L => (6 attempts)
Let the water be distributed in the 3 jars(separated by commas) as below.
Initially:
0L,0L,9.5L, Distribute them into 5L and 3L jars as below:
5L,3L,1.5L Now throw away the 1.5 (wastage = 1.5L) so the distribution becomes
5,3,0. From here...
5,0,3
2,3,3
2,0,6
0,2,6
5,2,1
4,3,1 (Four is captured inside the 5L can in a total of 8 steps.)
4 steps :
1.First fill 3L and pour it into 5L and now 5L container has 3L and 2L empty
2.another 3L into 5L, so 1L will be left in 3L container
3.clear the 5L and fill it with 1L that was left in 3L
4.fill 3L into the 5L , hence 4L.
The total number of steps in your procedure is 9 as opposed to 4 that you are thinking.
Each of the step listed by you indeed involves two steps:
>>. 1.First fill 3L and pour it into 5L and now 5L container has 3L and 2L empty
Filling the 3L can is one step and pouring it into 5L is another step
>> 2.another 3L into 5L, so 1L will be left in 3L container
Refilling 3L is one step and filling up 5L from 3L so 1L remains in the 3L is yet another step
>> clear the 5L and fill it with 1L that was left in 3L
Two steps again
4. fill 3L into the 5L , hence 4L.
How can you directly fill 3L into 5L can? You first have to fill the 3L can and only then will you be able to measure 3L. This step actually involves 3 steps:
I. First, you transfer the 1L from 3L can to 5L can
2. Fill up the 3L can
3. Transfer from 3L can to 5L can, which will then make up 4L
It can be done in following way but I don't know its minimal wastage or not...
I am assuming we can only use two jar not 3
5,3,9.5
-------------------
0,3,6.5
3,0,6.5
3,3,3.5
5,1,3.5
1,0,3.5
1,3,0.5
4,0,0.5
done
I understand wastage is 9L..., but this the only way I could think of using two jars
Everyone is over thinking the problem. Assuming you have 5L and 3L beaker, and 9.5L of water....
1) Put the 3L beaker inside the 5L beaker, fill the remaining space inside the 5L beaker to the rim with water. You should now have 2L of water in the 5L beaker, transfer that water into the 3L beaker.
2) Repeat the same motion, you should now have 2L of water inside the 3L beaker, and another 2L of water inside the 5L beaker, which equals a total of 4L!!!
two steps, no water wasted. Don't over think life.
Step1 : Pour from 3L to 5L.
Step2 : Now 5L has 3L and 3L flask empty. Fill the 3L flask and pour into 5L flask.
Step3: Now 5L flask is full and 3L flask has 1L remaining.
Step4: Throw the water from 5L flask and get the 1L from 3L flask.
Step5: Fill the 3L flask with water and pour into 5L which already has 1L in it. Altogether it makes 4L in flask 5L.
step1: pour 5L in 3L (you will have 2L in 5L container)
step2: empty 3L container and now pour remaining 2L (from 5L container ) in 3L
Step3: fill 5L container again
step4: pour 5L container now in 3L container which already has 2L water, so it can only contain extra 1L.
So in 5L container you will have exact 4L
step1: pour 5L in 3L (you will have 2L in 5L container)
step2: empty 3L container and now pour remaining 2L (from 5L container ) in 3L
Step3: fill 5L container again
step4: pour 5L container now in 3L container which already has 2L water, so it can only contain extra 1L.
So in 5L container you will have exact 4L
first fill the 3L and pour it in the 5L and again do the same by filling the 5L completely now there is 1L of water is remaining in the 3L and pour it to the 5L and now fill the 3L and pour it again in the 5L now there is exactly 4L of water in the 5L bottle with the wastage of 5L of water
vol(A) - 5, vol(B) - 3, water thrown/wasted
0, 0, 0
5, 0, 0
2, 3, 0
2, 0, 3
0, 2, 3
5, 2, 3
4, 3, 3
in A I get 4L with wastage of 3L
Fill the 5. Pour slowly into the 3 until the bottom of the 5 container is almost exposed. That is 2.5. Using the water already in it, do the same with the 3, that is 1.5. Pout that into the big container 2.5+1.5 = 4
total wastage 2.5-1.5 = 1 litre.
4 steps
/
/ /
/ /
/
A(5L) B(3L) C(Big)
- Laks January 11, 2014---------------------------
0 0 9.5
0 3 6.5
3 3 3.5
5 1 3.5
0 1 3.5 (5L waste)
1 3 0.5
4 0 0.5