Pregunta de entrevista de IIT Academy

Dynamic programming related question with optimising it further