Build a recursive function. I still can't believe this is used as an interview question. In my 25+ years as a software engineer, I can count the number of times I have use one on one hand. Actually on half a hand... There's is always a better choice than recursion.