Google interview question

Leetcode array question with a some minor changes