Interview Prep

Four Prisoners Hats Puzzle: Answer [Solved]

Four prisoners hats puzzle answer featured image: four prisoners in a line, two black hats and two white hats

Prisoner 2. In the four prisoners hats puzzle, the second prisoner from the back is the one who speaks, and his hat is the opposite color of prisoner 3’s hat. Prisoner 1’s silence tells him everything he needs to know.

Four prisoners stand in a line, and one correct answer sets all four free. The puzzle is a famous logic test, reported as a Google interview brainteaser and as an IndiaMART interview question. It turns on a single idea: silence can carry information. Once you see that, the answer falls out in three short steps.

The Four Prisoners Hats Puzzle, Step by Step

A jailer lines up four prisoners on a staircase, all facing the same way. He puts a hat on each prisoner. There are exactly two black hats and two white hats, and everyone knows the counts. Nobody knows the color of his own hat. The rules are strict: no talking, no turning around, and no touching a hat. As soon as a prisoner knows his own hat color for certain, he must say it. One right answer frees all four. One wrong answer ends all four.

  • Prisoner 1 stands at the back. He can see prisoners 2 and 3.
  • Prisoner 2 stands second from the back. He can see prisoner 3.
  • Prisoner 3 stands at the front, facing a brick wall. He can see nobody.
  • Prisoner 4 stands behind a wall of his own. He can see nobody, and nobody can see him.

Take one concrete arrangement to make it real. Suppose prisoner 3 wears a black hat and prisoner 2 wears a white hat. Prisoner 1 looks at the two hats in front of him: one white, one black. He cannot tell his own color, so he says nothing. Prisoner 2 watches prisoner 1 stay silent. That silence is the clue. Prisoner 2 looks at prisoner 3’s black hat and knows his own hat must be white. He speaks, and all four go free.

What Prisoner 1’s Silence Means

If prisoners 2 and 3 matched, prisoner 1 would speak at once

Start with prisoner 1, the only prisoner who sees two hats. There are two black hats and two white hats in total. If the two hats in front of him were the same color, both hats of that color would be used up. His own hat would have to be the other color. For example, if prisoners 2 and 3 both wore black hats, prisoner 1 would know at once that his own hat is white. He would speak in the first minute, and the puzzle would end there.

Silence is information

In our example, prisoner 1 says nothing. That fact rules out a whole set of arrangements. Prisoners 2 and 3 cannot be wearing the same color, because prisoner 1 would have spoken if they were. Therefore prisoners 2 and 3 wear different colors. This is the heart of the puzzle. Prisoner 1 gives no answer, yet his silence answers a question. Logicians call this common knowledge: everyone knows the rule, everyone knows that everyone knows it, and so a silence speaks as loudly as a word.

Why the Four Prisoners Hats Puzzle Answer Works in Every Case

There are only six ways to hand out two black hats and two white hats among four prisoners. Run the same logic through all six, and the puzzle always resolves. The table below shows each case.

Black hats worn byPrisoner 1 seesWho speaksWhat he says
Prisoners 1 and 2Black and whitePrisoner 2Black
Prisoners 1 and 3White and blackPrisoner 2White
Prisoners 1 and 4White and whitePrisoner 1Black
Prisoners 2 and 3Black and blackPrisoner 1White
Prisoners 2 and 4Black and whitePrisoner 2Black
Prisoners 3 and 4White and blackPrisoner 2White

In short, the puzzle always has a speaker. In four of the six cases, prisoner 2 speaks after prisoner 1’s silence. In the other two cases, prisoner 1 speaks at once because the two hats in front of him match. Either way, nobody guesses. Every answer follows from facts the speaker can see, plus one silence he can hear.

The Trap Most Candidates Fall Into

Most candidates who miss the four prisoners hats puzzle make the same three mistakes. Firstly, they guess. A guess has a 50 percent chance of killing all four prisoners, and the puzzle forbids guessing. Secondly, they name prisoner 1. Prisoner 1 sees the most hats, so he looks like the strongest candidate. In most cases, however, he sees one black hat and one white hat, and that tells him nothing about his own hat. Thirdly, they forget prisoner 4. He stands behind a wall, sees nobody, and hears nothing useful. He can never answer, and the puzzle does not need him to. The winning move is to ask what each prisoner knows, and what each prisoner’s silence proves.

Two Fair Questions About the Four Prisoners Hats Puzzle

How long must prisoner 2 wait?

This is the sharpest question about the puzzle, and it deserves a straight answer. Prisoner 2 can only use prisoner 1’s silence after enough time has passed for prisoner 1 to think. The puzzle assumes a fair interval, often stated as one minute, and it assumes all four prisoners reason at the same speed. Without a set interval, the silence proves nothing, because prisoner 1 might still be thinking. In an interview, say this out loud. It shows you check the assumptions behind a puzzle instead of taking them for granted.

Why can prisoner 4 never answer?

Prisoner 4 stands behind a wall. He sees no hats at all, and he cannot hear anything that tells him his own color. Even after prisoner 2 speaks, prisoner 4 learns nothing about his own hat, because the answer names prisoner 2’s color, not his. He is in the puzzle to test whether you notice who has information and who does not. The correct answer never needs him.

What changes with three prisoners?

The same trick works with three prisoners, two black hats, and one white hat. Prisoner 1 sees two hats. If both are black, he knows his own hat is white, and he speaks at once. If they differ, he stays silent, and prisoner 2 uses the silence the same way. Prisoner 2 looks at prisoner 3’s hat and names the opposite color. The pattern is general: silence from the prisoner who sees the most narrows the field for the next prisoner in line.

What the Interviewer Is Testing in the Four Prisoners Hats Puzzle

The interviewer is not testing whether you have seen this puzzle before. Four qualities matter. Firstly, reasoning about other minds. You must track what each prisoner knows, not only what you know. Secondly, treating absence as data. Most candidates only use what they can see. The strong candidate uses what does not happen. Thirdly, discipline under pressure. A wrong answer kills four people, so the puzzle rewards a candidate who waits for certainty instead of guessing. Finally, clear communication. The interviewer wants to hear the chain in order: what prisoner 1 sees, why his silence matters, and what prisoner 2 concludes. State each step, and name the fact behind it.

Try Another Puzzle Next

If you liked the four prisoners hats puzzle, try the 100 prisoners hats puzzle next, where a single coded word saves 99 prisoners for sure. The blue-eyed islanders puzzle uses the same common-knowledge idea over 100 days, and the three logicians bar puzzle turns a single phrase, “I don’t know”, into a proof. Each one rewards the same habit: ask what the silence means.

Is prisoner 2 always the one who speaks?

No. In two of the six possible hat arrangements, prisoners 2 and 3 wear the same color, and prisoner 1 speaks at once. Prisoner 2 speaks in the other four cases, after prisoner 1’s silence. The puzzle is usually told with an arrangement where prisoners 2 and 3 differ, so prisoner 2 is the standard answer.

Is this the same puzzle as the 100 prisoners hats puzzle?

No. The 100 prisoners hats puzzle is a different classic. There, 100 prisoners stand in a line and each names a hat color in turn, using a parity code agreed the night before. The four prisoners hats puzzle uses silence as information and needs no code at all. Both puzzles share hats and a line of prisoners, and little else.

Could prisoner 3 ever speak first?

No. Prisoner 3 faces a brick wall and sees no hats at all. He has no information about his own hat, and no silence can help him, because prisoner 1’s silence tells him nothing he can use. He waits, like prisoner 4, for someone else to speak.

Sources: the question is reported as a Google interview brainteaser and as an IndiaMART interview question on Glassdoor. The solution above is original.

Enjoying this? Add StudyFromNotes as a preferred source on Google to see our latest notes and updates more often:

Leave a Reply

Your email address will not be published. Required fields are marked *