Microsoft interview question

Solve a state machine problem