Skip to main content
๐Ÿ“œ 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:

  1. 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.
  2. Name the data. Array vs ArrayList decides the loop family and the size API. String decides charAt/substring.
  3. 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?
  4. 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.