Goldman Sachs interview question

Two leetcode questions: 1 Medium, 1 Hard