Uber interview question

recursion question with DP follow up