Binary-search a monotone answer
Turn optimization into a decision problem with a proved truth direction.
Understand the idea
Define feasible(x) precisely. A minimum-capacity task often has false values followed by true values: larger capacity cannot hurt. Search for the first true with a lower midpoint, moving hi = mid on success and lo = mid + 1 on failure. Establish a feasible upper bound first.
Trace a small example
To find the smallest x with x ≥ 7 in [0, 12], test 6 (false), 9 (true), 8 (true), and 7 (true). A last-true search reverses the contract and needs an upper midpoint when assigning lo = mid, otherwise an interval of two candidates may never shrink.
Conditions and cost
A monotone predicate and valid bounds are prerequisites, not results of binary search. O(log range) checks cost O(checkCost × log range). Compute mid without an overflowing endpoint sum and make each branch reduce the candidate interval.
Can binary search safely find the first true in false, true, false, true?
Turn the idea into code
Find the minimum time to make 5 items using machines taking 2 and 3 time units per item.
Give me a hint
At time t, count floor(t/2) + floor(t/3).
Show the explained solution
At time 5 the count is 3; at time 6 it is 5. The count never decreases, so the first feasible time is 6.
Your notes
Mark complete when you can explain it yourself.