Goldman Sachs Interview Question

Array based leet code question.