Domanda di colloquio di Uber

Hard Leetcode question related to dynamic programming.