Thought Machine Interview Question

One string parsing algorithms question of medium difficulty.