Goldman Sachs Interview Question

the question was leet code easy