It's not a realistic assessment of skills though. You don't write code on a whiteboard for work, you do it in an environment you have setup to let you work most efficiently. You have the option to look up things you can't quite remember, do some research to see if there is anything you missed, take a quick break to clear your head, etc...
Plus, too often it devolves into a game of algorithm trivia with the interviewer. Gotta prove how smart* you are.
"So what have you been working on?" "Oh I was the lead engineer on our new backend system. Built it on top of X, built a custom foobar because we needed to scale Y functionality blah blah blah" "Oh cool, cool. We actually are looking at building something similar. Well anyway enough of this obviously useless information exchange, here's a question about graph searches".
*smart may be substituted for grinding out leetcode questions for weeks beforehand, at the interviewees discretion.