Amazon interview question

Leetcode medium question about array manipulation