Datadog interview question

One easy algorithm problem. Then another one which was a bit more complex (requiring recursion).