Binary Search on Answer
Search the answer range when feasibility changes monotonically as the candidate answer changes.
The prompt asks for the minimum possible maximum, maximum feasible minimum, or another optimized value with a yes/no feasibility test.
How to approach it
Set valid lower and upper bounds, test the midpoint, and shrink toward the smallest or largest feasible answer.
The hardest part is proving monotonicity and writing a correct feasibility check; bounds and integer rounding matter.
Practice question
A worker must ship weights [3, 2, 2, 4, 1] in 3 days, preserving order. What is the smallest daily capacity that works?
weights = [3, 2, 2, 4, 1], days = 3Give your answer before revealing the explanation.Show a hint
Binary search capacity from the heaviest package to the sum of all packages.
Show an answer
6. Capacity 6 allows [3,2], [2,4], [1]; capacity 5 needs 4 days.
Binary Search on Answer at work
A warehouse must ship packages weighing [4, 3, 5, 2] in order within 2 days. What is the smallest truck capacity that can meet the deadline?
Show one possible approach
7. Capacity 7 ships [4,3] on day one and [5,2] on day two. Capacity 6 would need three days because the last two packages total 7.
Practice next
Use these problem IDs to find additional practice for this pattern: