Would you pass this tech interview test?


25 Jul 2016

Don’t perform well under pressure? Can you imagine how bad it would be if you were asked to do maths in a high-stress situation? Imagine no more.

This week’s maths problem is inspired by a question asked at real-life tech interviews. How would you do?

Concerning jelly beans

You are presented with three jars of jelly beans. One contains apple-flavoured jelly beans, another is full of blueberry, and a third is full of cherry.

Each jar contains exactly 100 jelly beans. All the jelly beans look the same, and the jars have no labels.

You turn away and, while your back is turned, your friend takes one jelly bean from each jar. They then place the three jelly beans back in the three jars, but in such a way that each of the jelly beans ends up in a jar other than the one it came from. They then give each jar a thorough shake.

Your friend asks you how many jelly beans from each jar you wish to eat. They pick up the number of jelly beans you ask for, and put them on the table in front of each jar.

What is the smallest number of jelly beans you should ask for so as to be absolutely sure after eating them that you know the original flavour of each jar?

Scroll down for the solution.

This week’s puzzle is provided by Dr Anca Mustata, lecturer in mathematics at University College Cork (UCC), who is actively involved in the Maths Circles initiative, the Mathematics Enrichment programme in UCC and the Irish Mathematical Olympiad. The mislabelled jars problem was brought to Mustata’s attention by Dr Anthony Cronin, manager of the Maths Support Centre in University College Dublin.

Maths: jar of jelly beans

Jelly beans, via Shutterstock

Solution

The answer is six – three from one jar and three from another.

For the sake of discussion, let’s call Apple ‘A’, Blueberry ‘B’ and Cherry ‘C’. Let’s also assume that the jelly beans are distributed as follows:

Jar 1: 99pc A, 1pc B

Jar 2: 99pc B, 1pc C

Jar 3: 99pc C, 1pc A

Choosing three jelly beans from Jar 1 will yield either AAA or ABA. You would therefore know that the jar’s original flavour was A.

It makes no sense to choose more than three jelly beans, as that would not give you any additional information. On the other hand, choosing two jelly beans could yield AB, and then you would not know whether A or B was the original flavour.

Choosing three jelly beans from Jar 2 will yield either BBB or BCB. Hence, you would also know the original flavour of this jar – B. As with Jar 1, taking only two jelly beans may not definitively identify the original flavour, so you need three.

A simple process of elimination will then allow you to deduce that the original flavour of Jar 3 was C, without you having to draw any jelly beans from that jar.

Main image via Shutterstock