Goldman Sachs Interview Question

Q: string manipulation optimization leet code medium question.