Pergunta de entrevista da empresa Uber

Hard Leetcode question related to dynamic programming.