Pregunta de entrevista de Google

Data Structures and Algorithms question. String manipulation question