Goldman Sachs interview question

Some Leetcode questions, medium level