Pergunta de entrevista da empresa Datadog

Solve a classic recursion problem, then come up with a non recursive solution.