IBM interview question

dynamic programming problem