
Read one failure closely
Expand a failed visible case. Record the arguments, expected output, actual output, and the first behavior that looks wrong.
ExampleIn Two Sum, [3, 2, 4] and target 6 should return [1, 2]. Returning [0, 0] suggests your code paired the first value with itself.
Isolate the cause
Use the visible case’s debug control, Quick Test, or Sandbox where available. Trace state before and after the line you suspect.
ExampleAt index 0 the seen map should be empty. Inserting 3 before checking the complement allows the lookup to find index 0.
Fix one behavior and rerun
Move the lookup before insertion, or make the smallest change that restores the intended invariant. Rerun the failing input and then all visible cases.
ExampleTry [3, 3] with target 6 as a custom case. You should return [0, 1] and still pass the previously working cases.
Check your work
You can identify the first incorrect state, show the fix with a test, and rerun the visible suite.
Try it yourself
Try a second bug in Two Sum. Use a truthiness check for an index retrieved from a map, then run the visible example [2, 7, 11, 15] with target 9.
- What to look for
- The value 2 is stored at index 0. A truthiness check can skip it. Use an explicit membership check and rerun the case to confirm [0, 1].