Datadog Interview Question

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