Moogsoft interview question

DP, recursion