Domanda di colloquio di SAP

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