Smooth Commerce interview question

I solved one algorithm about arrays