Goldman Sachs interview question

Array based leet code question.