Goldman Sachs interview question

Easy to medium leetcode question