Skip to main content
๐Ÿ“œ WAYPOINT LESSON

Off-by-One and Boundary Tests

โญโญโญ advancedโณ 30 min read๐Ÿ“ Lesson 187 of 281

Difference arrays, half-open ranges, and reversed reads โ€” the bugs that pass every symmetric test you try by hand.

Design tests that kill the bug class

Off-by-one survives [l, r] = [1, n] tests because both directions are symmetric. Kill it with asymmetric ranges: [1,2] then [2,4] on n = 4. Half-open semantics: an interval [a, b) ending at t does not overlap [t, ...]. Reversed l/r reads pass palindromic data โ€” always include one lopsided op.

โšก Now practice

Ready to Code
Bug HuntPair sums at 4e9, subtree sizes on a 200000-node bamboo, and 200000 difference-array ops.
3 challenges ยท ยท ~110 min