Question d’entretien chez SAP

Dynamic programming question to be solved on a text editor explaining the logical reasoning for the answer.