Microsoft Interview Question

Question on DP based problem.