Pregunta de entrevista de Thought Machine

One string parsing algorithms question of medium difficulty.