Goldman Sachs interview question

two leetcode questions from two people