Tower of Hanoi with Glass Constraints
Tower of Hanoi glass flipping puzzle is a medium quant interview question on Brain Teasers.
This brain teaser involves a group of prisoners and a single shared object whose state can be flipped or left alone whenever a randomly chosen prisoner is brought in. Each prisoner, when selected, may also choose to make a one-time global declaration about the process having reached a particular milestone that concerns everyone's participation. They are allowed to agree on a strategy beforehand, but have no communication afterward except through the evolving state of that object. The puzzle asks for a protocol that guarantees eventual success regardless of the random selection order.
The solution leans on ideas from distributed algorithms and coordination under uncertainty: designing roles, using a single shared bit as a communication channel, and enforcing rules that prevent double-counting. It tests whether a candidate can construct an invariant-based scheme, reason about worst-case randomness, and ensure termination with certainty rather than probability. Interviewers are watching for a clear division of responsibilities, careful handling of edge cases, and a rigorous argument that the protocol neither fails early nor gets stuck forever.
What it tests
This problem class is governed by the idea of encoding collective progress through a shared, observable state that all agents can affect but only in a controlled, coordinated way. The key is to use a single global variable (like the state of the glass) as a communication channel, allowing distributed agents to signal their unique participation without direct interaction. By assigning asymmetric roles—one agent as the accumulator or counter, and the rest as contributors—it's possible to aggregate information about the system's state over time. The principle works because the system's randomness (who is chosen each minute) is counteracted by deterministic, pre-agreed rules that ensure each agent's contribution is counted exactly once. This transforms a problem of hidden information and uncertainty into one of controlled information flow, making it possible to guarantee a safe outcome.
Practise this question with written feedback, or hear it in a spoken mock interview.
Get started free