Solve this standard array manipulation problem and explain the time and space complexity of your solution.