Airbnb interview question

Medium difficulty recursion problem