Pregunta de entrevista de Amazon

Leetcode medium question about array manipulation