The largest that works: first fail, minus one.
transcript
You want the largest value that works. Longer pieces give fewer pieces. The template finds the first true. Flip the question.
Ribbons of nine, seven and five. We want six equal pieces, as long as possible. Here are the pieces for each length.
At least six pieces: yes, yes, yes. Then no, from length four. The check passes, then fails.
Search for the first length that fails. Start hi one past the longest ribbon. That length gives no piece at all. Return lo minus one.
The search ends with lo at four. Four is the first length that fails. So the answer is three. At length three, the ribbons give six pieces.
What if no length works? Then even length one fails. Lo stays at one, and the answer is zero. It happens when you ask for too many pieces.
The largest that works is the first fail, minus one. It works for any check that flips once. Full breakdown in the lecture.