AceTheInterview
Jobs in Pune | Work better in teams | Socialize with friends | Submit Q&A | Tell a friend
Search site for 

Top 100 Interview Questions & Answers in a convenient and easy to read book!

“I bought this guide a few days ago to prepare for my interview with Oracle. Many of the questions they asked me were from this guide. I found this book absolutely great!”

– Ravi, California

Read more comments...

Interview Questions And Answers RSS Feed

Answers »

  1. Submitted By: Rajiv Nistala — September 16, 2007
    +1 votes
      + -

    1) You can start the bottom of the building and keep throwing the bulb from every floor. This will use only 1 bulb. In this scenario the worst case is if the bulb breaks on the 100th floor for which you would have done 100 iterations.
    2) You can throw from a fixed interval let say every 10 floors. So if the bulb doesn’t break from the 40th but breaks at the 50th floor, you can use the second bulb to check from 41st to 49th floor iteratively to get the minimum floor from where it breaks. Here the worst case if the bulb breaks at the 99th or 100th floor for which you would have done 19 iterations. But in this case how do you know 10 is the fixed interval size which will give you the least number of iterations.

  2. Submitted By: Xavier Cam — September 29, 2007
    +8 votes
      + -

    The first bulb should be thrown at fixed intervals of 10 floors until it breaks (10, 20, 30,…). If the bulb breaks, the second bulb should should be used to check all the floors between the floor it broke at and the previous interval. So if it broke at floor 40, floors 31 to 39 should be checked.

    Proof: Assume X is the size of the fixed interval (in my answer it is 10). Then the most number of iterations that will be done: x+100/x

    Want to minimize x+100/x.

    Let f = x+100/x
    f’ = 1-100/x^2

    Minimum occurs when f’ = 0 => 0 = 1-100/x^ => x = 10

    Therefore, interval of 10 should be used.

  3. Submitted By: garrincha — October 7, 2007
    +34 votes
      + -

    Both answers are unfortunately wrong, because they assume a fixed interval size. The right answer is as follows:
    The interval size must decrease by one with increasing tries, since one try less is available. This way the number of
    trials is much better distributed.
    For example, if we start with the 15th floor, if the bulbs not breaks, the next one is the 29th, then the 42th and so on.
    Now we only have to determine the optimal starting floor(
    and thus the initial interval).
    We have to calculate

    min (sum(i= 0 to n) i >= 100), n an integer
    n
    min (n*(n+1)/2 >= 100)
    n
    n = 14.
    Thus one throws the first bulb till it breaks from the floors
    14,27,39,50,60,69,77,84,90,95,99,100, and the second one from the last floor level before breaking in 1-storey steps.
    The worst number of trials is 14 (much better than the 19
    iterations in the answers above).

  4. Submitted By: avu — October 11, 2007
    -6 votes
      + -

    I have an objection to the above answers..

    let’s say the 8th floor is the minimum. In this case, the 10 floors method takes 1+8 = 10 throws.
    The 14 floors solution takes 1+8 = 10.

    Here’s my strat,

    Throw bulb no. 1 (B1) from every (3*n)th floor where n runs from 1 to 33(in this case).

    If B1 breaks on the 3rd floor, try B2 on the first floor. If B2 breaks on the first floor then we are done, else floor 2 is the answer.

    If B1 breaks on floor 6 (remember only 3*n floors are being considered for B1), try B2 on the 4th floor (i.e. (3*n -2) for the nth iteration). If B2 breaks on 4th we are home, else floor 5 is the answer.

    So, if floor 8 is the answer, I’ll try B2 on 3,6,9 and I’ll use B1 on floor 7.
    This takes only 4 iterations.

    But, the above solutions beat this approach when the destiny floor is higher up in the skies.

    My conclusion: The best approach must incorporate a way of guiding the search towards an answer. Right now, we are just sweeping across without a map.

  5. Submitted By: Sumanth — November 4, 2007
    -10 votes
      + -

    Using Fibonacci search is the best way to find the solution. This method is faster than traditional binary search algorithms, with a complexity of O(log(x))

  6. Submitted By: Anjali — February 17, 2008
    -25 votes
      + -

    I think that bulb should be dropped from half height
    like if total 100 floors are there then drop it from 50 floor, if it breaks take second bulb drop it from lower half i.e. 25 floor else if it won’t break drop from 75 floor and by taking average again repeat same procedure
    IT’S disadvantage is it will take more number of bulbs but number of iterations will be least

  7. Submitted By: Bajeed — July 22, 2008
    -8 votes
      + -

    The worst case of 14 is not accurate, the worst case will be 15 in that case. If the bulb breaks in 14th floor then we need 15 tries. First try at 15th the first bulb breaks, then we will start with second bulb from 1st floor until 14th, so we need worst case scenario of 15 tries.

  8. Submitted By: reshika.a.g — August 26, 2008
    -11 votes
      + -

    this is similar to a binary search algorithm. if there are 100 floors, throw from 50 th floor.if it does not break, continue in the upward direction to throw from (the median of 100 and 50-tat s 75) else,if bulb breaks,continue with 25 th floor, repeat the same for each of the iterations..

  9. Submitted By: Kiran — September 4, 2008
    -2 votes
      + -

    This problem can be solved using Divide-and-Conquer method and Minimization method.

    If 100 floors re divided into k sub-groups then the number of tries needed are 100/k+k-1

    d/dk(100/k+k-1) = 0
    => -100/k^2 +1 = 0
    => k = 10

    Number of iterations = 100/10 + 10 -1 = 19.

  10. Submitted By: Gayatri — March 22, 2009
    -6 votes
      + -

    Throw from 25 ——->
    if it breaks … next one you can try 1 to 24 turns
    Worst case 24 + 1 = 25———-(1)

    if it does not break on 25 go to 50 ——–>
    if it breaks … next one you can try 50 to 25 turns
    Worst case 24 + 1 = 25———-(1)

    Similary 75 and 100 in steps of 25.

    Therefore worst case you will find in 25+3 =28 turn.

  11. Leave an Answer/Comment

    To prove you're a person (not a spam script), type the security text shown in the picture. Click here to regenerate some new text.
    Click to hear an audio file of the anti-spam word

Our Sponsors
Our Sponsors
Contact Us | FAQ | Sitemap | Terms of Use | Privacy Policy | Tell a Friend

Copyright © 1999-2006 Jeeve Technologies LLC. All rights reserved.