Meta interview question

Leetcode hard question on array manipulation