Pergunta de entrevista da empresa Media.net

One question on simple implementation on dynamic programming.