Frage im Vorstellungsgespräch bei Amazon

Question related to Dynamic Programming which was HARD difficulty