Pergunta de entrevista da empresa Epic

There is an question to output something using dynamic programming. I wrote a long code.