Pregunta de entrevista de BNY

coding question based on dynamic programming