Pregunta de entrevista de Atlassian

It was a Dynamic programming problem.