Showatech Interview Question

They asked to solve the problem in dynamic programming