Code360 powered by Coding Ninjas X Code360 powered by Coding Ninjas X
Table of contents
Problem Statement
Frequently Asked Questions
How to master the Puzzle questions?
Why are puzzles important in interviews?
How to answer the puzzle questions in an interview?
Is it common for puzzles to be asked in interviews?
What exactly are puzzle questions?
Last Updated: Mar 27, 2024

Gates of Heaven

Master Python: Predicting weather forecasts
Ashwin Goyal
Product Manager @
Interview Puzzles


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

Ninja dies and reaches the gate of heaven. He has three doors in front of him out of which only one of them leads to heaven. 

Out of the other two gates, one leads to hell for one day and then back to the gate and one leads to hell for two days and then back to the gate.

If he chooses one of these three gates, the gates are shuffled when he returns back.

How long is Ninja expected to take to reach heaven on average?

Output Format: Integer

Illustration Image

Take your time and think. 

Okay, let us now discuss the solution: 

Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job


Suppose the average days spent is X. 

=> ⅓ of the cases he reaches heaven in zero days. ( ⅓ * 0)

=> ⅓ of the cases it takes ( 1 + X). ( ⅓ * (1+X))

=> ⅓ it takes ( 2+X) days. ( ⅓ * (2+X))

The probability of choosing any of the three cases is ⅓. To find the average time, we need to take all the cases into consideration. 

X = ⅓ * 0 + ⅓ * (1+X) + ⅓ * (2+X)

X = 0 + ⅓ + X/3 + ⅔ + X/3

X = (2X + 3)/3

3X = 2X + 3 

X = 3 

Hence, on average it will take 3 days to reach out to heaven. 

Let us now discuss the FAQs related to puzzle questions:  

Check out this problem - Check If A String Is Palindrome

Frequently Asked Questions

How to master the Puzzle questions?

Understand all of the Terms given in the question.
Take your time reading the question.
Make a list of all the possibilities.
Visualize the problem statement using pen and paper.
Practice daily to enhance your problem-solving techniques. 

Why are puzzles important in interviews?

In software engineer interviews, puzzles are a realistic way to test your lateral thinking. It demonstrates to the interviewer your ability to solve real-world problems and think creatively.

How to answer the puzzle questions in an interview?

Consider the problem.
Ask for clarification.
Make use of what you know.
Describe your reasoning.
Provide a solution.

Is it common for puzzles to be asked in interviews?

The majority of the puzzles asked in interviews are designed to assess your ability to think "differently." They rarely have a single correct answer to which they can refer. You can use your own logic to solve it. So looking at hundreds of puzzles online and double-checking their solutions isn't going to cut it.

What exactly are puzzle questions?

This type of question consists of items belonging to different groups or possessing different qualities being given along with some clues with which the candidate is required to group and analyze the given items and answer the questions accordingly.


In this article, we discussed the interview-based puzzle question - Gates of Heaven which is solved by taking all the cases into consideration.  

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 Data Structure and Algorithms, Competitive Programming, Operating Systems, Computer Networks, DBMS, etc. as well as some Contests, Test Series, Interview Bundles, and some Interview Experiences curated by top Industry Experts only on Coding Ninjas Studio.

Happy Learning!

Previous article
100 People in a Circle
Next article
Fastest Horses
Live masterclass