Pergunta de entrevista da empresa JPMorganChase

A Dynamic Programming based problem which I have to code on Codepair platform