Capacity To Ship Packages Within D Days
Signals to notice
Brute force first
Try every capacity from max(weights) to sum(weights). Linear search through all feasible capacities. That instinct is useful because it follows the prompt literally, but it usually keeps revisiting work the problem is begging you to organize.
The key insight
Binary search on the capacity. For each candidate, greedily simulate shipping: pack packages until the day's capacity is full, then start a new day. If you need ≤ D days, the capacity works. Once you hold onto the right piece of information from moment to moment, the problem feels less like trial and error and more like following a shape that was there all along.
What must stay true
If capacity c works (ships in ≤ D days), any capacity > c also works. This monotonicity validates binary search. The minimum valid capacity is the answer. When you keep that truth intact, each local choice supports the larger solution instead of fighting it.
Easy way to go wrong
Setting the lower bound to 1 instead of max(weights) — you can't split a package, so the minimum capacity must be at least the heaviest package. The fix is usually to return to the meaning of each move, not just the steps themselves.