๐ WAYPOINT LESSON
Diagnose before code
โญโญ intermediateโณ 12 min read๐ Lesson 125 of 256
Return type โ data โ composition: naming the machines from the contract.
No module label this time. Each problem below mixes several machines; your first job is diagnosis, not coding. The two-minute ritual:
- Read the contract; name the return type. A count โ counter machine. A String โ builder machine. A boolean โ flag/existence. A position โ sentinel. A new collection โ accumulator.
- Name the data. Array vs ArrayList decides the loop family and the size API. String decides charAt/substring.
- Name the composition. Does the answer need a pass over data AND a pass over positions (columns)? A filter inside a scan? A max over computed per-row values?
- Only now write code โ the machines assemble themselves once named.
Example diagnosis: "Return the number of distinct values in the strictly-positive half of the grid's first row." โ return type: count (counter). Data: array row. Composition: filter (positive) + dedup (backward-looking pairwise). The code is three machines you already own โ the reading is the work.