Infosys interview question

To solve one dp question