The point of that is to see you implement a relatively simple algorithm, not for you to make something perfect.
Exactly this. We ask candidates to code a simple function. It's not to see if they know some trivia or if they can place all the semicolons correctly, it's to see if they understand basic programming concepts. Once they get the basic code down, then the interview can start. What's the algorithmic complexity? How does it handle edge cases? How does it handle malformed input? Does it scale? How would you test it?
Yeah, we know you're never going to actually code a toy problem like this on the job. But we only have an hour or two to explain the problem, have you code it, and discuss your solution. We don't have time to have you code anything non-trivial.
Later, when we finally got enough budget for me to be on the other side of the table, I was shocked at how many then recent CS grads (early 2Ks) failed at both.
Tell me about it. I've been to on-campus career fairs where by the end of the day I just want to say, "Pick a language. Write Hello, World." Because I've talked to graduating seniors who couldn't do it! Literally, they could not code Hello, World in the language of their choice. WTF, people? What have you been doing for the past four years?
I've been in the industry for just over 25 years. I've worked for start-ups and I've worked for mega-corps. My current gig has by far the best group of programmers I've ever worked with. I attribute this to our interview process, including the coding portion. No apologies for it. When done right it really works.