Amazon Interview Question

Medium difficulty recursion code question.