Thought Machine interview question

One string parsing algorithms question of medium difficulty.