Binary Search on Answer
Recognize it when 'is x feasible?' is monotonic in x; binary search the answer space with one feasibility check per probe.
Decision · step 2 of 7Search on the Answer: Least ship capacity in 5 days
Range 10 to 55, probe capacity 32. Pack greedily, starting a new day whenever the next package would overflow: 1+2+3+4+5+6+7 | 8+9+10, 2 days. Within 5, so 32 works and anything bigger is unnecessary: hi = 32.
What you will see
The array being searched is the range of possible answers; each probe runs a feasibility check.
Cost
| Best | O(log range * check) |
|---|---|
| Average | O(log range * check) |
| Worst | O(log range * check) |
| Space | O(1) |
How you work with it here
play it through, step one change at a time, run it on your own input, predict what happens next.
Screen readers: Pattern lessons reuse the canonical algorithm's semantics and add a spoken "recognize this when" cue.
Reduced motion: Inherits the canonical algorithm's strategy.