Dynamic Programming21 sections · 916 units
Open in Course

Common Mistakes

What can go wrong

1.1. Forgetting to verify convexity. If g(k)g(k) isn't convex, binary search won't find the right λ\lambda.

2.2. Not handling ties properly. When multiple kk values give the same cost, track counts carefully.

3.3. Wrong binary search bounds. Start with reasonable bounds on λ\lambda: typically [0,max_cost][0, \max\_cost].

4.4. Precision issues with floating-point λ\lambda. Sometimes you need integer binary search with careful rounding.