Goldman Sachs interview question

Dynamic Programming.