Goldman Sachs interview question

The first problem was a heap problem.