Google interview question

leet code hard on dynamic programming