Goldman Sachs Interview Question for Developer Program Engineers


Country: India
Interview Type: In-Person




Comment hidden because of low score. Click to expand.
9
of 11 vote

If the third prisoner sees that both prisoners in front are wearing same-colored hats, then he knows he must be wearing a different-colored hat.

If he does not, and does not guess correctly, then the remaining two prisoners must be wearing a red and a blue hat. The second prisoner can see the hat in front of him and knows that his own hat must be the opposite color. So if he sees a red hat he answers blue and vice versa.

- rax March 05, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
4
of 4 vote

Let A B C in line with C in front. Let D be somewhere else.

Now if B and C has same colors. A can immediately speak his color. B and C will know their colors and will speak theirs. Finally D will.

If both has different, A will be silent. After some time, B will realize his condition and can guess that his color is different from C's.
Therefore B will speak out his. C will listen B's answer and will come up with his color. Eventually all the prisoners will go free.

- Ashish Anand March 05, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

for the second case, when B and C are wearing different colored hats. They manage to guess their own color, But what about A and D in that case ?

- Mystry March 05, 2013 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

here if you see the question carefully , "If any prisoner can figure out and say to the jailer what colour hat he has on his head all four prisoners go free" , so even if one prisoner says correctly, it is enough. We need not know all the four guys having which hats.

- Anonymous March 05, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

if all sittinging same line but in same direction like A,B,C if A&B or B&C wearing same color hats.at that time if A & B (red or blue)same color then A will know all remaing three people color then he will tell.
otherwise B & C same color(red or blue) at the time B will know C also having same color and reamin two A & D are different color the that he tell to jailer.

- ram97 March 06, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

If in a line where A can see B & C. And B can see only C. D is away.

A -> B -> C

If A see red-red or blue-blue then he knows his is blue or red respectively. If A sees red-blue or blue-red keeps silent.

If A keeps silent then B knows the hat on his is different than than on C. So, if B sees red on C's head he know his is blue and vice versa.

All prisoners go free.

- Anonymous May 25, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Question looks too simple... and the 4th prisoner has no role in the solution... I believe some constraint is missing in the question.

- Satish June 26, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Hey satish. Everything is given in the problem. See the solution below.

If in a line where A can see B & C. And B can see only C. D is away.

A -> B -> C

If A see red-red or blue-blue then he knows his is blue or red respectively. If A sees red-blue or blue-red keeps silent.

If A keeps silent then B knows the hat on his is different than than on C. So, if B sees red on C's head he know his is blue and vice versa.

All prisoners go free.

- PCB August 12, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

What is the need to place 4th person in another room??? I think some thing is missing in question..

- Sunilkumar Kunapareddy November 06, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Here is the actual puzzle :

An executioner lines up 100 prisoners single file and puts a red or a blue hat on each prisoner's head. Every prisoner can see the hats of the people in front of him in the line - but not his own hat, nor those of anyone behind him. The executioner starts at the end (back) and asks the last prisoner the colour of his hat. He must answer "red" or "blue." If he answers correctly, he is allowed to live. If he gives the wrong answer, he is killed instantly and silently. (While everyone hears the answer, no one knows whether an answer was right.) On the night before the line-up, the prisoners confer on strategy to help them. What should they do?

- rockstar February 17, 2014 | Flag Reply


Add a Comment
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.

Learn More

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.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More