Google interview question

An Array leetcode medium question