It takes a lot of practice and is a skill in itself. Most interviewers would fail a similar live coding exercise if they interviewed at another company without practice.
The goal is to keep yourself grounded and focus on the problem at hand. Practicing under these circumstances of course makes it easier.