Domanda di colloquio di Amazon

Hard dynamic programming question, see leetcode most frequently asked