Table of contents
1.
Introduction
2.
Problem statement
3.
Solution 
4.
Frequently Asked Questions
4.1.
Why should we have to solve a puzzle?
4.2.
Is programming similar to puzzles?
4.3.
Do solving puzzles improve our coding skills?
5.
Conclusion
Last Updated: Mar 27, 2024

Policeman and the Prisoner

Author Shivam Verma
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?
Interview Puzzles

Introduction

Puzzles are good exercise for the brain. They help in enhancing the cognitive abilities of the brain helping with Problem Solving and related skills. There are numerous types of puzzles; each one having a logic inherent to itself which helps in cracking it. A good puzzle well is actually like a good mystery that we may have read about or watched on TV. It has the finest of hints which help in reaching its solution.

The following article discusses one such puzzle so let's get right to it.

Problem statement

A Prisoner has been scheduled to be punished by the Police and as a result, they had to give a statement. However, there is a catch if the statement the prisoner makes is true, the prisoner will be hanged to death whereas if the statement is false, the prisoner would be shot to death.

The Prisoner wants to stay alive. What statement should they make such that they live after making the statement and save themself?

Solution 

Reply as per the prisoner “I will be shot dead.”

If the policeman marks the statement as true, the prisoner would be hanged to death, violating the statement.

If the policeman marks the statement as false, the prisoner would be shot dead, which will support the assertion. 

Check out this problem - 8 Queens Problem

Frequently Asked Questions

Why should we have to solve a puzzle?

The main reason behind solving puzzles is to test the depth of your thinking. It also confirms that you were not a nerd, and you can think beyond the imagination.

Is programming similar to puzzles?

Yes, programming is similar to a puzzle based on data and math that works in the background. 

Do solving puzzles improve our coding skills?

Yes, it does improve our competitive coding skills. Competitive coding is all about solving a puzzle using a computer. 

Conclusion

In this article, we have extensively discussed the problem statement and solution regarding the Prisoner and Policeman Puzzle.

Recommended Readings:


Do check out The Interview guide for Product Based Companies as well as some of the Popular Interview Problems from Top companies like Amazon, Adobe, Google, etc. on Coding Ninjas Studio.

Also check out some of the Guided Paths on topics such as Interview Puzzles, Data Structure and Algorithms, Competitive Programming, Operating Systems, Computer Networks, DBMS, System Design, etc. as well as some Contests, Test Series, Interview Bundles, and some Interview Experiences curated by top Industry Experts only on Coding Ninjas Studio.

Do upvote our blog to help other ninjas grow. Happy Coding!

Live masterclass