If their response is "this is stupid, no one has to know how to do this" and storm out with the same indignation that is present in half of these comments then they are not the ones who dodged a bullet.
It depends on the position you apply for, I'd say.
Some jobs require C++ and algorithmic skills. If you don't know how to write a basic algorithm in C++, then you might not be the best fit - and you might not want to join the company as a junior developer.
That being said - sorry to hear that was your experience. That shouldn't have happened, but it does.
If it's down to syntax errors, and the logic is correct, what the heck does it matter? Almost everyone writes code in an IDE that will deal with those syntax errors.
One writes code that cannot be compiled while the other does. Who scores higher?
Now, let's say you are a big company and have 100 applications for that position and do the math...
EDIT: I noticed you edited your post so it looks less inflammatory. Not cool.
Which is probably the root problem. Almost all tech hiring is carried out like a war between companies that want results and candidates who don't want to be treated like shit.
Because BFS has two approaches - 1.) I know BFS or similar example and will write it with no thinking 2.) I am figuring it out in head while saying things to keep you pleased.
You don't need to know employee internal thought process. Practically, BFS tests whether you are able to BFS, which is cool by me. It is simple enough so that people who were really unable to learn it should really be filtered out.
(It is ok to not know name, obviously. Just ability to find a thing in datastructure should be question.)