Pergunta de entrevista da empresa ByteDance

I was asked to solve a medium-level problem related to string manipulation. The interviewer provided hints when necessary and was mainly interested in my thought process and the efficiency of the solution.