Goldman Sachs interview question

leetcode style question, medium-hard, regarding arrays.