Saturday, February 2, 2008

Break the jars

There are 27 floors in a building and you have been given three jars. You have to find from which floor the jar will break when dropped. If you start from the bottom most floor and drop the jar and keep raising the height, you will require only one jar, however the maximum attempts you will require can be 27.

Now with three jars you can reduce your attempts easily sacrificing all three of them. The question is - How many attempts are required ?


2 comments:

Nitai said...

On a maximum, 8 attempts, I guess. 1st at 14th floor, 2nd at 7th floor assuming the worst case of the 1st jar breaking. Again assuming the worst case that the 2nd jar breaks, next 6 attempts at floors 1 to 6.

Rohit Malshe said...

The correct answer is 6.

Divide those into intervals of 9 first. Attempt first jar at 9, then at 18. If you break it at 9, then attempt at 3, 6. If you break it at 18, attempt the second at 21 and 24.

If you break the second at 3, then attempt at 1, 2.
If you break the second at 6 then attempt at 4, 5.
If you break the second at 21 then attempt at 19, 20.
If you break the second at 24 then attempt at 22, 23.
If you did not break the second at any floor, attempt at 25, 26, 27.

Maximum is calculated when all your attempts do not break any jars. So it won't break at 9 and 18. Then it won't break at 21, 24. Now you will try on 25, 26. Worst case - it won't break there.

If it was sure that it was to break at some floor - then the floor is 27. So maximum attempts required are 6 !