Before you solve the case
Read the Complement Evidence
Every Two Sum investigation begins with three questions:
- What two positions must the Answer Space return?
- What suspects live inside the unsorted Problem Space?
- What previous evidence must be recorded so the current Candidate can find its Complement?
Case File #002 teaches you how to read a pair-sum problem and prove why the route needs a Recorder before writing code.
How to Analyze Two Sum
The Correct Code Framework treats the problem statement as an evidence locker. Two Sum is not solved by pattern memory. It is solved by asking what evidence must be remembered.
1. Extract the contract: The answer must return two indices, not the values themselves.
2. Map the environment: The input is an unsorted integer array and a target sum.
3. Derive the invariant: The candidate needs a complement where candidate + complement == target.
4. Prove the Recorder: Since the complement may have appeared earlier, prior values must be preserved as value -> index.
Two Sum Simulator
Watch the Scanner bring one suspect into the Evaluation Frame as the candidate. The Recorder keeps earlier values so the candidate can ask whether its complement has already been seen.
Problem Statement
Given an array of integer numbers and an integer target, return the indices of the two numbers such that they add up to the target. Each input has exactly one solution, and the same element may not be used twice. Return the two indices once the matching pair is discovered.