Amazon interview question

Medium difficulty recursion code question.