Goldman Sachs Interview Question

a question on dynamic programming and other on hashmap.