Pregunta de entrevista de Uber

Hard Leetcode question related to dynamic programming.