3 ms·
I agree it's very easy to make an off-by-one mistake in binary search. (Related article: [1]) But an interview candidate showing something that is almost right
by quietbritishjim 5y ago
I agree it's very easy to make an off-by-one mistake in binary search. (Related article: [1]) But an interview candidate showing something that is almost right and then has enough self-awareness to say "but I'm sure there's an off by one error in there somewhere" has given a really good overall answer in my books. I think there's still value in asking the question because that sort of answer constrasts against candidates who flounder completely (which is more common than you'd imagine).
A common counter argument is that a bad interviewer wouldn't accept an answer that has minor bugs in it like that. But I don't buy that counter argument, because a bad interviewer could misjudge candidates regardless of the interview format.
[1] https://reprog.wordpress.com/2010/04/19/are-you-one-of-the-10-percent/ https://reprog.wordpress.com/2010/04/19/are-you-one-of-the-1...