Skip to main content
šŸ“œ 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.

  1. Boundary off-by-one. Exclusive/inclusive endpoints, hi = n vs hi = nāˆ’1, empty-range handling. Signature: fails on tests whose answer sits AT a boundary.
  2. 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.
  3. Signed/type overflow. int32 accumulation over 2Ā·10^9. Signature: fails only at scale, and the wrapped value is often negative.
  4. Ordered/unordered counting. xĀ·(xāˆ’1) vs xĀ·(xāˆ’1)/2. Signature: exactly double (or half) on inputs with ≄ 2 relevant items.
  5. Greedy exchange violation. A sort key missing the term the exchange proof needs. Signature: fails on an adversarial small case with two "competing" items.
  6. 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.
  7. 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 Code
Clinic DrillsThree drills: staleness signatures, the all-distinct blind spot, and exact-doubling diagnosis.
3 challenges Ā· Ā· ~20 min