Pergunta de entrevista da empresa BNY

coding question based on dynamic programming