Goldman Sachs interview question

Leetcode questions, one easy one medium