Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Table of contents
1.
Introduction
2.
Problem Statement
3.
Solution Approach
4.
Frequently Asked Questions
4.1.
What is the definition of a puzzle?
4.2.
What are the benefits of puzzle-solving?
4.3.
Do software companies frequently ask for puzzles?
4.4.
What are some of the most common interview questions and puzzles?
4.5.
Will you be asked puzzles in interviews all of the time?
5.
Conclusion
Last Updated: Mar 27, 2024

Jelly Beans Jars

Leveraging ChatGPT - GenAI as a Microsoft Data Expert
Speaker
Prerita Agarwal
Data Specialist @
23 Jul, 2024 @ 01:30 PM
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

You've got three jars that are all mislabeled. The first features peanut butter jelly beans, the second has grape jelly beans, and the third has a combination of the two (not necessarily half-half mix).

How many jelly beans would you have to pull out to figure out how to fix the labels on the jars?

The following are the jar labels:

  • 1st Jar: Peanut Butter.
  • 2nd Jar: Grapes
  • 3rd Jar : P.b. / Grape 

 

The answer is a number. If the number is an integer, enter it without any decimal places. Infinity should be output if the answer is Infinity.

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
Bootcamp

Solution Approach

 

Illustration Image

The solution to the Jelly Beans Jars puzzle is only one jelly bean we would have to pull out to find out how to fix the labels on the jars.

The approach is that if we pull out one jelly bean and found to be of P.B., from Jelly Beans Jar number 3, which has a label of P.B. / grape, then that JAR3 will be Peanut butter because it is mislabeled.

So we can easily say the correct labels of the other two JARs by exchanging the JAR 2 name from Grape to P.B. / Grape because peanut butter will be found in JAR 3, and also, it can not be Grape because it is mislabeled.

And finally, JAR1 is of Grape.

This is the solution to the Jelly Beans Jars puzzle.

Check out this problem - 8 Queens Problem

Frequently Asked Questions

What is the definition of a puzzle?

A puzzle is a game that uses words, toys, questions, and other items to help us improve our problem-solving skills.

What are the benefits of puzzle-solving?

People's problem-solving skills improve when they solve puzzles. It also helps a person's logic.

Do software companies frequently ask for puzzles?

Since problem-solving is an essential part of programming, all software firm applicants are regularly put to the test using puzzle problems. As a result, it's not uncommon for software companies to ask candidates to solve riddles during their interviews.

What are some of the most common interview questions and puzzles?

The following are some of the most common interview questions:
Bag of Coins Puzzle
Crossing the Bridge Puzzle
Heaven or Hell Puzzle
Gold Bar Cut Puzzle
Three Mislabeled Jars
Man Fell in Well Puzzle

Will you be asked puzzles in interviews all of the time?

While most interviewers do not specifically request puzzles, they are common, and some interviews may even contain specialized puzzle-solving sections. It's always good to be prepared if anything unexpected occurs.

Conclusion

In this article, we have extensively discussed the problem of Jelly Beans Jars with a solution.

Recommended Readings:


You can explore more interview questions Coding Interview Questions and answers for practice | Python, Java & C++  you can also try our Free Mock Test Series.

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, 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 Learning!

Live masterclass