Pergunta de entrevista da empresa Amazon

Some dynamic programming on words.