Lyft interview question

Medium dynamic programming question from leetcode.