Solve a classic string manipulation or array-based problem using an optimal time and space complexity solution.