Write an algorithm to solve a specific array-manipulation problem, and analyze its time and space complexity.