Google interview question

question based on dynamic programming