๐ WAYPOINT LESSON
The four elimination probes
โญโญ intermediateโณ 12 min read๐ Lesson 126 of 256
Empty, single, all-equal, order: killing near-miss answers by contract.
Exam questions present plausible near-misses. The skill is elimination by contract, not by vibes. The four elimination probes:
- The empty probe. What happens with length 0 / "" / empty list? A solution that reads element 0 unguarded dies here.
- The single probe. One element: does a seeded-max or adjacency scan handle it? Adjacency loops from 1 or to length โ 1 do nothing โ correct or not, depending on the contract.
- The all-equal probe. Every value identical: tie-breaking (strict vs non-strict) decides.
- The order probe. Run the trace on a sorted and a reverse input: order-dependent bugs (first vs last, min vs max) expose themselves in one of the two.
Apply to this candidate solution for "index of the smallest value, earliest on ties":
int best = 0;
for (int i = 1; i < arr.length; i++) {
if (arr[i] <= arr[best]) { best = i; } // probe 3: fails
}
The all-equal probe {7, 7}: i=1, 7 <= 7 true, best becomes 1 โ the
LAST tie. Contract says earliest. The <= must be <. One probe, one
character, one eliminated answer.
โก Now practice
Ready to CodeMixed clinicDiagnosis drills, probe writing, two-pass reproduction, three-machine composition.
5 challenges ยท ยท ~65 min