Goldman Sachs Interview Question

It is a CoderPad test.