Question d’entretien chez Amazon

Medium difficulty recursion code question.