Explain your approach to solving a medium-difficulty array manipulation problem and walk through your solution's time and space complexity.