GlobalLogic interview question

Some random array based Leetcode question.