Uber interview question

Haker Rank medium to difficult Dynamic Programming question.