I would rather have a programmer look for a library function to do the task, and understand its specification and all its cases, for correct use.
Failing that, I'd expect them to research the solutions online (and offline if necessary). Find some suitably licensed code snippet or failing that, carefully implement it from a quality specification somewhere (an original paper, good textbook or whatever).
The last thing we want is programmers regurgitating from memory what they think are the correct algorithms.
The vanishingly small number of times I've implemented a binary search from scratch over the past several decades, I cribbed it from somewhere. I needed the algorithm not only to find the item but also correctly indicate where a not-found item would be inserted. I don't want to reinvent annoying little crap like that from scratch, only to get some detail wrong, just like whoever did it first, fifty years before me!
Here is a good exercise for an interview. Give someone an obtusely written, confusing specification for an API, together with a task to implement with that API: watch how they defend the code against the corner cases, and deal with the ambiguities. The task would be "make a best effort to solve the task, and write down any questions about the API which block the completion of the task."
Because that's what we deal with: we read docs, try to use things, hit issues, and then research (online, with vendors, source code, etc) to get unblocked.
I might have a part II to the question where some source code of the API is revealed, and the interviewee would have an opportunity to continue. (So they don't walk away with a sense of incompleteness.)