Goldman Sachs interview question

lc style questions as normal