Microsoft interview question

Simple 1D Dynamic Programming Question