Goldman Sachs Interview Question

The first problem was a heap problem.