Goldman Sachs interview question

sending the coding challenge first