Pregunta de entrevista de Datadog

Implement a recursive algorithm to satisfy the required outcome.