1.

Still not satisfied and willing to give up, Sultan now brings up 9 jars filled with 4, 2, 6, 7, 3, 4, 5, 8 and 3 bananas respectively. In one minute Tintin can either double the content of one jar, or eat one banana from each jar, and gives him a time limit of 90 minutes. Can Tintin empty all the jars using these moves in the given time? If yes, then give the minimum time required by him (in minutes) to empty the jars?Answer 00 if it is not possible.

Answer»

Solution : First NOTE that a jar shall not become zero with other jars being nonzero.(Think !).Yes mario can always empty the jars. Basic idea is to reduce one from every jar until a jarcontains only one, then double that jar and continue. This will ensure emptying, though notin minimum STEPS.For minimum steps­ we shall reduce the unnecessary steps.The method is to first double each jar until it reaches a number less than or equal to the highest number, then deduct all jars by one until a jar becomes one OR if a jar can again be doubled under above condition (note that this doubling will not add any EXTRA work & infact reduce some.). Then check above rule after every deduction & double the necessaryjars.For eg, consider only 2 jars­ with 1 4 as initial counts. Then he shall FOLLOW these steps­ 
1. Double the jar 1 (gives 2 4) 
2. Double the jar 1 (gives 4 4) 
3. Reduce both jars one by one `(3 3 ­gt 2 2 ­gt 1 1 ­gt 0 0)` (4 times)Which gives 6 as the minimum steps to empty the jars.eg 2: in the case 2 6 8, the number shall drop as follows (11 steps)­`2 6 8 gtgt 4 6 8 gtgt 8 6 8` (double each jar CLOSE to highest number)`8 6 8 ­gt 7 5 7 ­gt6 4 6 ­gt 5 3 5 ­gt4 2 4` (reduce all ONLY until there is a double possibleagain!)
` 4 2 4 gt gt 4 4 4 ­gt3 3 3gt gt2 2 2gt gt1 1 1gt gt0 0 0` (then follow same procedure)
Now that you have an idea, the original question will be easy to answer.

Which gives that minimum 19 steps are required for emptying the jars.


Discussion

No Comment Found

Related InterviewSolutions