You are standing before two doors. One of the path leads to heaven and the other one leads to hell. There are two guardians, one by each door. You know one of them always tells the truth and the other always lies, but you don’t know who is the honest one and who is the liar.
You can only ask one question to one of them in order to find the way to heaven. What is the question?
This is one of the classic puzzles asked in Infosys interview.
One possible question to ask to one of the guardians is:
“If I asked the other guardian which door leads to heaven, what would they say?”
If you ask this question to the liar, they will lie about what the truth-teller would say, and if you ask this question to the truth-teller, they will tell the truth about what the liar would say.
So, let’s say you ask the question to the guardian in front of the two doors who is the liar. If you asked the liar which door leads to heaven, they would point you towards the door to hell. But since they have to lie about what the truth-teller would say, they would actually point you towards the door to heaven. So, in this case, you would choose the opposite door that the liar points you to.
On the other hand, if you ask the question to the guardian who is the truth-teller, they would honestly point you towards the door to hell, but since they have to tell the truth about what the liar would say, they would also point you towards the door to hell. In this case, you would also choose the opposite door that the truth-teller points you to.
So, no matter which guardian you ask, the answer will lead you to the door that leads to hell, allowing you to choose the other door as the path to heaven.