Solve a classic string manipulation or array-based problem, focusing on optimizing space and time complexity.