Pregunta de entrevista de Google

String manipulation with less time complexity