When I ask these types of questions in an interview, I don’t expect an answer from memory. If you have good fundamental understanding of algorithms it is a good way to see how someone thinks.
The biggest problem I see is that candidates can’t explain their thinking, and thus it is hard to get much out of it. Those that do well can talk it through and explain why they approached the problem a certain way. I don’t care if it is 100% correct.
I’m sure others are looking for different things, but this is the intention of these types of questions IMHO