GeeksforGeeks » Interview Questions

Microsoft Interview Question for Software Engineer/Developer about Puzzle

(6 posts)
  • Started 9 months ago by praveen
  • Latest reply from Shantanu

Tags:

  1. praveen
    guest
    Posted 9 months ago #

    A bunch of men are on an island. A genie comes down and gathers everyone together and places a magical hat on some people’s heads (i.e., at least one person has a hat). The hat is magical: it can be seen by other people, but not by the wearer of the hat himself. To
    remove the hat, those (and only those who have a hat) must dunk themselves underwater at exactly midnight. If there are n people and c hats, how long does it take the men to remove the hats? The men cannot tell each other (in any way) that they have a hat.

    FOLLOW UP Prove that your solution is correct.

  2. Manik
    guest
    Posted 9 months ago #

    After C days.
    Consider a person A wearing the hat.
    A shall see C-1 hats.
    If A thinks he is not wearing the hat, then he would expect the others to realize that they are wearing a hat in C-1 days, and have a dunk after C-1 days.
    But since they did not, that means A is also wearing a hat, so they shall dunk in C days.

    Move C from 1,2, 3... to verify the solution.

  3. ravi
    Member
    Posted 9 months ago #

    I think this question is incomplete but still... lets answer

    1)
    As no one can tell other that he has a hat, but will see C-1 hats around.
    And only those can dunk who are having hat, but there is no way to know for a person that he has hat.
    hence it's a dead lock....

    2)
    If all are known that there are C hats, the person having hat can see C-1 hats then it's easy to infer he is having a hat and will dunk at first midnight
    similarly all can know before the first midnight....
    Hence only one midnight is required to remove all hats

  4. sonam
    guest
    Posted 9 months ago #

    2*C

  5. VD
    guest
    Posted 5 months ago #

    Sonam can you explain

  6. Shantanu
    guest
    Posted 5 months ago #

    Manik has the right answer already. C+1 days or as he said, after C days. This question has many varieties ranging from evil imp releasing the dwarf to unfaithful husbands in a village.


Reply

You must log in to post.

RSS feed for this topic