Pergunta de entrevista da empresa Amazon

1-dimensional DP with additional optimizations