Code360 powered by Coding Ninjas X Code360 powered by Coding Ninjas X
Table of contents
Problem Statement 
Frequently Asked Questions
What are some of the puzzles asked in an interview?
Why do interviewers ask riddles?
What are stress interviews?
Last Updated: Mar 27, 2024

Marbles in the Jar

Author Harsh
1 upvote
Master Python: Predicting weather forecasts
Ashwin Goyal
Product Manager @


One technique to assess your capacity for problem-solving is through puzzles. These are challenging questions that encourage logical thinking. You must be concentrated and cautious under any circumstances in order to solve any puzzle. It demonstrates how composed you will be under pressure. In this blog, we are going to discuss a very famous marbles in the jar problem which tests your logical and mathematical ability.


marbles in jar

Let’s get started with the puzzle.

Problem Statement 

Ninja has 50 red marbles and 50 blue marbles in the jar ( two separate jars ). He must arrange the marbles in the jars so that when he randomly selects one marble out of one jar, the probability of it being red is maximized. When choosing a marble, he will first select a jar at random and then select a marble from that jar at random. He can arrange the marbles in the jar in any way he sees fit, but each marble must be placed in a jar. Compute the highest possible probability.

Note: Remember to round off the answer to two decimal places if needed. For example, if the answer is 6/7, the response should be 0.86


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


To get the maximum possible probability we can try different combinations like putting all the red marbles into JAR A and all the blue ones into JAR B. Then our probability will be

P(red marble): P(Jar 1) * P( red marble in Jar 1 ) + P( Jar 2 ) * P( red marble in Jar 2 ).

P(red marble): (½ * 1) + (½ * 0) = 0.5

As you can see from the above equation the probability that we are getting is 50%. You can try any other combinations like keeping 25 red marbles in jar A and 25 in jar B still you won’t get the maximum probability. So what’s the most optimal way to solve the problem?

What if you put all of the marbles in jar A keeping just one red marble in jar B? As only one marble will be chosen at random, you will always have at least a 50% chance of acquiring a red marble in this manner. There are 49 red marbles left in the other jar, giving you a nearly equal chance of choosing one (49 out of 99).

So the maximum probability will be:

P( red marble ) = P( Jar A ) * P( red marble in Jar A ) + P( Jar B ) * P( red marble in Jar B )

P( red marble ) = (½ * 1) + (½ * 49/99)

P( red marble ) = 74/99

P( red marble ) = 0.75 (rounded off to two decimal places)

We get 0.75 as our probability of getting the red marble which is the maximum possible probability we can achieve.

In this manner, you can solve the puzzle marbles in the jar.

Check out this problem - 8 Queens Problem

Frequently Asked Questions

What are some of the puzzles asked in an interview?

Most of the puzzles asked during interviews are designed to gauge your level of mental ability. Here are some common puzzles asked in an interview:

  • Crossing the Bridge Puzzle
  • Marbles in the jar
  • Heaven or Hell Puzzle
  • Man Fell in Well Puzzle
  • Birthday Cake Puzzle

Why do interviewers ask riddles?

Brain teaser questions are used in interviews to gauge a candidate's capacity for critical thinking, creativity, and problem-solving under pressure.

What are stress interviews?

An applicant is thrown off balance and placed in an unpleasant situation during a stress interview. It is intended to demonstrate how a candidate responds under pressure, manages stress, and resolves conflicts at work.


In this article, we have extensively discussed a very famous puzzle problem marbles in the jar asked in many interviews.

If you think this blog has helped you enhance your knowledge about the puzzle marbles in the jar and if you would like to learn more, check out our articles Camel and the Banana PuzzleTic Tac Toe PuzzleCheryl’s Birthday PuzzleMex Puzzle, and many more on our Website.

Visit our website to read more such blogs. Make sure that you enroll in the courses provided by us, take mock tests and solve problems available and interview puzzles. Also, you can pay attention to interview stuff- interview experiences and an interview bundle for placement preparations. Do upvote our blog to help fellow ninjas grow.

Nevertheless, you may consider our paid courses to give your career an edge over others!

thank you

Please upvote our blog to help other ninjas grow.

Happy Learning!

Previous article
One Mile on the Globe
Next article
100 People in a Circle
Live masterclass