š WAYPOINT LESSON
The Bug Catalog
āāā advancedā³ 13 min readš Lesson 238 of 281
Seven recurring categories cover most wrong solutions ā each with its signature and its smallest counterexample shape.
The Bug Catalog
Almost every plausible-but-wrong solution falls into one of seven categories. Learn the signatures; recognition beats re-derivation.
- Boundary off-by-one. Exclusive/inclusive endpoints,
hi = nvshi = nā1, empty-range handling. Signature: fails on tests whose answer sits AT a boundary. - Tie-breaking. Comparison uses
>where>=is required (or vice versa) ā or the sort key ignores a secondary criterion. Signature: fails when equal keys exist; passes on all-distinct data. - Signed/type overflow. int32 accumulation over 2Ā·10^9. Signature: fails only at scale, and the wrapped value is often negative.
- Ordered/unordered counting. xĀ·(xā1) vs xĀ·(xā1)/2. Signature: exactly double (or half) on inputs with ā„ 2 relevant items.
- Greedy exchange violation. A sort key missing the term the exchange proof needs. Signature: fails on an adversarial small case with two "competing" items.
- State staleness. A visited-set or memo reused across queries, or updated too early/late. Signature: the second query in a batch is wrong while the first is right.
- Direction confusion. Undirected edges added one-way; rows/columns transposed; parent/child flipped. Signature: asymmetric inputs break, symmetric ones pass.
The discipline: when you locate a bug, name its category AND write its smallest counterexample. Both together are the vaccine.
ā” Now practice
Ready to CodeClinic DrillsThree drills: staleness signatures, the all-distinct blind spot, and exact-doubling diagnosis.
3 challenges Ā· Ā· ~20 min