LinkedIn interview question

It is a basic Dynamic Programming question.