Goldman Sachs interview question

a question on dynamic programming and other on hashmap.