Infosys interview question

Problem related to dynamic programming