I suppose it depends on whether the purpose of the exam is to see if you know how to write working code to solve new problems or how to look up known solutions to well-known problems. Both are valuable skills, but they are definitely not the same skill. Perhaps telling the difference is one reason interviews frequently include in-person programming challenges rather than using take-home exams.
In most cases the right way to do a binary search is not to copy and paste a binary search implementation from Stack Overflow (https://stackoverflow.com/a/41956372 is similar to the formulation I gave above), but to call a binary-search library function. If calling a library function isn't the solution the interviewer is looking for, probably they wouldn't be satisfied with you searching for it on Stack Overflow either.