IBM interview question

Dynamic programming related coding question.