13/41
Part 2 of 7 · Binary searchLearn and do
In Java, C and C++, (lo + hi) / 2 can overflow
In Python, (lo + hi) // 2 is safe, because Python's integers don't overflow. In Java, C and C++ they do. That line sat as a real bug in the JDK's own binary search for about nine years. Its author explains that it fails when lo + hi is bigger than the largest positive int.
In those languages, write lo + (hi - lo) / 2. An interviewer who works in one may ask why you didn't.
In the editor, write the loop in last_at_or_before(times, t). It prints the latest change at or before 250, before 99, and at 160.