Showatech interview question

They asked to solve the problem in dynamic programming