Let me start out by saying i am not a big fan of interview brain teaser questions.  I understand why people like them; you get to see how someone reasons something out, how they work a problem with little or no background knowledge. However I’d rather give someone some code and ask them to figure that out as it’s much more likely to show whether they can solve programming problems.

However with that rant out of the way, my view is irrelevant. A large number of companies still love to ask these so it’s good to run through a few before you go in for your interview. If you’re lucky one that you know will come up, but more likely it will just help you to get into mindset of solving puzzles.

# Two Ropes

This is a very classic puzzler which I always forget the answer to.

“You have two pieces of string. If you light the string at one end it will take exactly 1 hour to burn through.  However, the string does not burn evenly, sometimes burning faster and sometimes burning slower.  The only guarantee is it will take 1 hour to burn the whole string.

With only 2 pieces of string and a lighter, measure out 45 minutes”

Break the units of the question down. We have two string to measure out 1 hour, and we need to come out with 45 minutes. 45 minutes can be broken down into 30 minutes and 15 minutes.  How can we get those two units?

The 30 minutes is relatively easy. By lighting one of the strings at both ends that gives us exactly 30 minutes. But how do we get the extra 15 minutes? We can’t fold the string in 4 due to the uneven burning.  Our options are only lighting one end of a string or lighting two ends.

If we could have a string of 30 minutes we could burn that at both ends to get 15 minutes. How do we get a string of 30 minutes?  At the start of the lighting light the second string from only one end.  When the first string burns out at 30 minutes the second string will be 30 minutes long. We can then light the other end to get 15 minutes!

# The Fox, The Hen and The Grain

There’s a ton of “cross the bridge” type question variations like this.

“You need to cross a river which is too deep and the current too fast to swim through. You have a fox, a hen and some grain The only option is a small footbridge which can only cope with you carrying one item over at a time.  If you leave the fox and hen together the fox will eat the hen. If you leave the hen and grain together the hen will eat all the grain.

How do you transport them over?”

When I think about this the standout information is that the hen is the most problematic animal; it could beeaten by the fox or it could eat the grain. Therefore it’s the only option to take over first. Only the fox and grain are safe together.  So when returning to the start, which do you take?  The answer is it doesn’t matter;  because neither can be left with the hen you will have to bring the hen back with you. Let’s take the fox over and put it on the other side.  We then bring the hen back to the start and pick up the grain. We can safely drop this with the fox and then come back for the hen.

Trip 1: Hen Out, nothing back

Trip 2: Fox Out, Hen Back

Trip 3: Grain Out, nothing back

Trip 4: Hen Out.

# The Cube

“If I have a 10 x 10 x 10 cube made up of 1 x 1 x 1 cubes and I paint the outside bright green, on how many cubes are there paint?”

A fun spatial reasoning exercise! There’s a bunch of ways to figure this out, and I never remember the easy one.

The cube is made up of 10 x 10 x 10 smaller cubes, so 1000 in total. The easiest way to calculate how many cubes are painted is to imagine removing all of the painted cubes from the cube. You’re left with another cube (like a russian doll) of 8 x 8 x 8 (because you’ve lost a layer on both sides. Don’t get caught out thinking the underlying cube would be 9 x 9 x 9).  8 x 8 x 8 = 512, 1000-512 = 488.

The other option is to actually count the sides; obviously the cubes overlap (the edge cubes appear on multiple sides).  If you take two opposing sides you have 2 10 x 10 sides (200 cubes).If you then take another 2 opposing sides you have 10 x 8 cubes that haven’t been touched. 2 x 10 x 8 = 160.  That leaves you then with 2 x 8 x 8 sides at 128. 128 + 160 + 200 = 488.

Image credit Kohlman Sascha