Microsoft interview question

Typical array manipulation from leetcode