Jelly Beans Jars Puzzle-Asked in Microsoft interview


You have three jars that are all mislabeled. One contains peanut butter jelly beans, another grape jelly jelly beans and the third has a mix of both (not necessarily half-half mix).

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

Labels on jars are as follows

Jar 1: Peanut butter

Jar 2: Grape

Jar 3: P.b. / Grape

Solution: 1

Only one jelly bean from the p.b./grape jar will do the trick.The trick here is to realize that every jar is mislabeled. Therefore you know that the peanut butter jelly bean jar is not the peanut butter jelly bean jar and the same goes for the rest.
You also need to realize that it is the jar labeled p.b./grape, labelled as the mix jar, that is your best hope. If you choose a jelly bean out of there, then you will know whether that jar is peanut butter or grape jelly jelly beans. It can’t be the mix jar because i already said that every jar is mislabeled.
Once you know that jar 3 is either peanut butter, or grape jelly, then you know the other jars also. If it is peanut butter, then jar 2 must be mixed because it can’t be grape (as its labeled) and it can’t be peanut butter (that’s jar 3). Hence jar 1 is grape.
If jar 3 is grape, then you know jar 1 must be the mix because it can’t be p.b. (as its labeled) and it can’t be grape (that’s jar 3). Hence jar 2 is peanut butter.

Thanks for Reading

Placewit grows the best engineers by providing an interactive classroom experience and by helping them develop their skills and get placed in amazing companies.

Learn more at Placewit. Follow us on Instagram and Facebook for daily learning.




Upskilling students for tech placements!

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Software architectures: What, why and do I need to pay attention to it?

Launch EC-2 instance & attach EBS volume using AWS CLI

Cloud Storage Picks with Alibaba Cloud

Why You Should Learn Coding as a Manager?

How to Implement Map Interface in Java?

Eagle Pcb Software Free

How to Manually Perform the VMware Tools Download from VMware Website: Full Guide

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store


Upskilling students for tech placements!

More from Medium

Two Numbers Puzzle

6 Steps template to actually pass your next FAANG technical interview. Part 1 out of 6.

The (Welcome) Death of the LeetCode Interview

Longest Increasing Subsequence Coding Question