Goldman Sachs Interview Question

leetcode style question, medium-hard, regarding arrays.