Monday puzzle: a really tough interview question
Many of my Monday puzzles have been technical interview brain teasers.
Sebastian emails me an interview question that is a really difficult math problem.
Hi Presh,
This is a question I once got asked in an internship interview. The interviewer told me it was a hard problem, that would take at least 20 minutes, but I still couldn’t solve it or come up with a decent formula under the stressful setting. Here it is:
You have a box with 30 shoe laces (or strings) in it. You can only see the ends of the strings sticking out, so you see 60 string ends total. Now you start tying them together until all ends are tied to another.
How many ways can you tie the shoe laces together?
What is the expected number of loops?
For instance there could be at least 1 big loop consisting of all the 30 strings but at most 30 individual loops when each end is tied to the end of the same string.
[Update 9-30]: I apologize for the confusion in wording. My solution below assumes left and right shoelaces are distinguishable. Arguably, left and right shoelaces should be treated as indistinguishable, and the question is about “how many structures” can be made. The comments below address both cases.
Can you figure it out?
I really enjoyed this question and I have spent over two hours working on it myself.
Definitely give this one a try before reading my hints and thoughts below.
Hint: work on lower cases
With math problems and interview brain teasers, there are often problem solving techniques that can help you get to the right answer.
My first thought was that working out the answer for 30 shoelaces would be hard. I would instead tackle smaller cases like considering 2 or 3 shoelaces and seeing if there is a pattern.
How many ways can you tie 2 shoelaces together?
I drew a figure like this and I counted the number of ways.

I noticed the leftmost shoelace end could connect to at most 3 spots: it could tie to the end of its own shoelace, or it could tie to one of the other two ends on the other shoelace.
After that, there would be just two ends remaining, making just 1 way to connect the loops.
This means there are exactly 3 x 1 = 3 ways to connect the ends when there are 2 shoelaces.
What about 3 shoelaces?
I tackled this case by drawing out the following diagram.

For the leftmost end, there are 5 different shoelace ends that it could connect to: either it could connect to the other end of its own shoelace, or it could connect to the four ends of the other shoelaces.
Once that end is tied, we have to consider how many ways the remaining 4 shoe lace ends could be tied. But in fact we have solved this problem already! This is exactly the number of ways 2 shoelaces could be tied together, which we found was 3 x 1 = 3.
Thus, the total number of ways for 3 shoelaces is 5 x 3 = 15.
Answer: How many ways can you tie the shoe laces together?
We can deduce a general pattern from these cases.
If there are n shoelaces, then there are 2n shoelace ends.
The first shoelace end can be connect to any of the other (2n – 1) ends.
Tying one end to another removes 2 ends. Thus, the next shoelace end can be connected to any of the remaining (2n – 3) shoelace ends, the one after that to the remaining (2n – 5) ends, and so on.
The general formula for n shoelaces is they can be tied together in:
Ways to tie n shoelaces = 1 x 3 x 5 … x (2n – 1)
In other words, we have a product of the odd numbers up to (2n – 1)
For 30 shoelaces, this is going to be a gigantic number. I will let WolframAlpha compute this one:
Question: What is the number of expected loops?
I have worked on this part of the question for a couple hours, and admittedly I have not come up with a solution.
I have worked out some smaller cases and formulas, however, and I am hoping someone can figure it out as you guys are so smart at solving puzzles.
In general, I would guess the expected number would be something like 4 or maybe 5.
Why so low?
The reason is there are a lot more ways to tie all the shoelaces into one loop.
For instance, consider 2 shoelaces. There is just 1 way to make the ends form two loops: you have to tie each to its own shoelace. But there are 2 ways you can form one big loop (if the shoelace ends are labeled Aa and Bb, then you can form the loops ABba or AbBa).
Above we showed there are 3 equally likely ways the 2 shoelaces can be tied. Thus, we can calculated the expected number of loops by:
loop size * number of ways / (total number of ways) = (2*1 + 1*2) / 3 = 4/3 = 1.3333
I have similarly worked out the case of 3 shoelaces. I will omit the details, but I manually counted the number of ways to make different loop sizes. There are 8 ways to end up with 1 big loop, 6 ways to end up with 2 loops, and just 1 way to end up with 3 loops. Thus, the expected number of loops is:
loop size * number of ways / (total number of ways) = (3*1 + 2*6 + 1*8) / 15 = 23/15 = 1.5333
What about 30 shoelaces? So far I have not been able to generalize this formula or figure out a nice way to count it. I am guessing there is some kind of recursion formula.
If you figure it out, please share in the comments or at least give us a hint–we’ll be extremely grateful.
Share this post:
Previous post: If a friend is wasting money, should you speak up or keep it to yourself?
Next post: Warren Buffett’s other political proposal




