Nagarro interview question

Standard question of Dynamic Programming.