Forgetting to prove QI: Don't assume it holds. Prove it for your cost function.
Wrong iteration order (Knuth): Process by length, not by then .
Off-by-one errors: Bounds are . Check edge cases.
Not storing opt: You need values to bound future searches. These optimizations are tricky. Test on small inputs first. Understanding this concept will help you solve more complex problems.