## Microsoft Interview Question for Software Engineer / Developers

Comment hidden because of low score. Click to expand.
5
of 5 vote

This solution is based on the assumption that the men know that there is atleast some one whose wife has cheated that is the value of c>0 but doesnt know the exact value of c. Also all can see whether a wife is dunked at midnight or not.

Lets consider the cases,

If c=1,

Then the person who has a crown on his head knows that there is atleast one such man whose wife has cheated. And moreover as he doesnt see any other with a crown, he will conclude that he is the 'one' and dunk his wife the 1st midnight.

if c=2,

Lets look at one of the 2 mens point of view. He knows that there is atleast one wife has cheated and he also sees a crown on another's head. He will assume that the other is going to dunk his wife on the 1st midnight. This is what the other person will also be thinking. Hence both of them will wait for the other to dunk their wives. However as this doesnt happen they will come to realize there is one other's whose wife has cheated and the other one is none but himself. Hence both will dunk their wives the 2nd midnight.

if c=3,

The man with the crown sees 2 others with crown and waits for 2 days without seeing any one dunking their wives and hence concludes his wife also cheated on him and hence he (along with the other 2) dunks his wife on the 3rd midnight.

generally,

similarly for any c all the men whose wife has cheated on them dunk their wifes on the cth midnight.

-Sudharsan

Comment hidden because of low score. Click to expand.
0

c=2 and c=3 in dese cases....c=2 every1 will be in doubt if they see a crown somebodys head

Comment hidden because of low score. Click to expand.
0
of 0 vote

Kiran - how would you do it in one midnight? If 10 people have crowns, each see 9 crowns - but they don't know how many crowns there are.

Comment hidden because of low score. Click to expand.
0
of 0 vote

Questions for interviewer...

1) If man is correct, does women leave with man?
2) If man dies, does women stay?
3) Limited to one midnight?
4) Wife's head wet till next midnight?

Comment hidden because of low score. Click to expand.
0
of 0 vote

5) Can dunk more than 1 wife simultaneously?
6) Can a man remember other men's deaths/corrections?

Comment hidden because of low score. Click to expand.
0
of 0 vote

Hi I am a bit slow on brain teasers

ur solution suggests n = c
wut if n - c = 10000?

wut would happen?

i might overlook some details, but anyhow, i want to post this q because my memory leaks.

hopefully i am wrong.
Gmac.

Comment hidden because of low score. Click to expand.
0
of 0 vote

Hi Sudharshan,

When c = 2, why would the 2 men go and sunk their wives. The first guy might still think there is only one guy among the whole crowd. Similary both might think and may not sunk their wives for ever. Your theory may not be true.

Thanks.

Kumar

Comment hidden because of low score. Click to expand.
0
of 0 vote

Sudharshan is right. one 1st day, both crowned men expect the other's wife to be dunked. But since this did not happen, it is obvious that there are 2 people crowned and it has to oneself. The other guy was thinking on the same logic as well.

Comment hidden because of low score. Click to expand.
0
of 0 vote

What is meant by cheated here? Is it kind of excahnging wives?

Comment hidden because of low score. Click to expand.
0
of 0 vote

i agree - here is a simpler explanation.

if there has not been a dunking on a previous night then every man who sees k crowns dunks their wife on the (k+1)th night.

proof: fix c>=1. The n-c men without crowns all see c crowns and the c men with crowns all see c-1 crowns. This second group all dunk on the cth night, so the first group never dunk.

-------------------

I don't know if this is permitted under the rules, but it can be done on the first night if one person can reveal one bit of information: for man i, let P_i be the parity of the crowns seen by i. Choose some guy A, who writes P_A into the sand. Then person i has a crown iff P_i + P_A = 1 mod 2, so each man can dunk their wives correctly on the 1st night.

Comment hidden because of low score. Click to expand.
0
of 0 vote

this is the same as the "blue eyes" problem, which is well known, so find that and you will get good explanations.

Comment hidden because of low score. Click to expand.
0
of 0 vote

It just takes 1 midnight to remove all crowns. For any two men A and B, A is allowed to ask B such a question: how may crowns does the genie put on the men according to your observation ? If B's answer is equal to what A himself observed, then A know eithor both A and B have a crown or none have; Otherwise, only one of them has a crown. So, A could find out if he has a crown because A also could observe if B has or not, although B is not allowed to directly tell A if A has or not. B could also ask A or anybody else the same question, and so on. Therefore, after the genie put crowns on the men by the midnight, the men could find out everything at once.

by Jimmy

Comment hidden because of low score. Click to expand.
0

You can't communicate how many crowns there are in any way.

Comment hidden because of low score. Click to expand.
-1
of 1 vote

It will take c midnights for the men to remove the crowns. And all will happen at the cth midnight.

-Sudharsan
TAMU.

Comment hidden because of low score. Click to expand.
-1
of 1 vote

it will take one midnight for crowns to be removed

Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

### Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

### Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.