I wonder what the expectation of the interviewer is on this. Virtually every single piece of code I'll ever write is going to have a a few off-by-one errors and probably other common bugs. That's why you do some basic validation and QA to find those bugs and fix them. The first pass isn't likely to even compile, but who cares? The compiler will tell you exactly why and you can fix that, too. Perfect code on a first try is a useless skill.
On the other hand, just understanding how the algorithm works is what matters. And binary search may have been "published" as an implementation on programmable electronic computers in the recent past, but it's a timeless and intuitive algorithm that I understood perfectly well when I was 4 years old and first learned to read and started looking up entries in the dictionary, encyclopedia, and phone book.
I quote from the thread: "binary search was first published in 1946 but the first published binary search without bugs was in 1962"