Round up for the largest yes
transcript
You search the largest yes. The loop never ends. Why?
For the smallest yes, round the middle down. On yes, set hi to mid. For the largest yes, round the middle up. On yes, set lo to mid.
Say lo is two and hi is three. A rounded-down middle is two. Setting lo to two changes nothing at all. The same range comes round again, forever.
Add one to the sum before you halve it. Now the middle is three. So lo moves, and the loop ends.
Ten to the nine lengths need thirty steps. A hang costs far more than that.
Always match the rounding to the loop you use. Test a range of two values. If it hangs, the middle is wrong.
A good search takes thirty steps. A hang runs out the whole time limit. So test a range of two values.
Match the middle to the loop. Test two values. Full breakdown in the lecture.