noon interview question

a DP problem to solve