Numbrs interview question

Dynamic programming hacker rank question.