Upstart interview question

A DP question of array