Pergunta de entrevista da empresa Amazon

Medium difficulty recursion code question.