Google interview question

it was Dynamic Programming question