WalzoneInterview Prep
📞 Interviewing soon? Practice with a realistic AI mock phone interview — it calls you, then scores you. First 15 min FREE →

Wall Street Quant · Puzzles & Problems · question 27 of 155

You are one of 100 prisoners. The warden, who is a bit eccentric, makes the following announcement. You may meet together today and plan a strategy, but after today you will be in isolated cells and will have no communication with one another. I have a fair coin and a light switch in a special cell. The coin flip will determine whether the switch is initially on or off. Each day, I will choose one of you at random and escort you to the special cell. There, you can toggle the switch if you wish, or you can leave it as it is. But you may do nothing else. If at any point any one of you declares to me, "We have all visited the special cell," and this statement is true, then you will all be set free. If the statement is false (that is, if one or more of you have not yet visited the special cell), then you will all be executed. You see the switch, but you do not see whether it changes day-to-day. What is your plan?

📕 Buy this interview preparation book: 155 Wall Street Quant questions & answers — PDF + EPUB for $5

To solve this problem, the prisoners can assign two roles and devise a plan accordingly. Let’s define the roles and plan:

1. **Counter**: A single prisoner is chosen during their initial meeting as the Counter. The Counter is the only person allowed to turn the switch off if it’s on (and only if the counter hasn’t yet reached 99).

2. **Non-Counter**: The remaining 99 prisoners have this role. They are allowed to turn the switch on only once, and only if they haven’t done so before.

The plan proceeds as follows:

1. The Counter starts with a mental count of 0.

2. When a Non-Counter prisoner visits the cell for the first time and sees the switch off, they turn it on if they haven’t done so before. This signals to the Counter that another prisoner was there.

3. If the switch is already on for Non-Counter prisoner on their first visit, they don’t do anything, not even on subsequent visits.

4. When the Counter visits the room and sees the switch on, they turn it off, and increase their count by 1.

5. Steps 2-4 are repeated. When the Counter reaches a count of 99, they announce that all prisoners have visited the special cell.

This method ensures that every Non-Counter prisoner will eventually contribute a count of +1 to the Counter’s tally. The Counter acts as a central data collection point who has access to the information about the prisoners’ visits. The execution time depends on how long it takes the Counter to reach a count of 99, which would take some time due to the random nature of prisoner selection. But, it guarantees that they will all be eventually set free.

One important point to note is that the initial state (on/off) of the switch will not affect the plan. The outcome is solely dependent on the prisoner roles and following their assigned actions.

Reading is step one. Saying it out loud is the interview. Our AI interviewer calls your phone and runs a realistic Wall Street Quant interview — then scores it.
📞 Practice Wall Street Quant — free 15 min
📕 Buy this interview preparation book: 155 Wall Street Quant questions & answers — PDF + EPUB for $5

All 155 Wall Street Quant questions · All topics