Microsoft interview question

Question on DP based problem.