What Value Is Needed?
Determine the complementary value required to complete the current candidate and reach the target.
CORRECT CODE INVESTIGATION / CASE FILE #002
Determine when an unsorted pair search requires preserved evidence.
THE ASSIGNMENT
Given an unsorted array of integers named numbers and an integer target, identify two elements at distinct index positions whose values add up to the target.
The required result is the two index positions—not the values themselves.
The investigation must establish how a valid pair can be identified without assuming that the array is sorted or that the elements appear in any particular order.
THE EVIDENCE
The problem statement establishes the following evidence:
A value examined earlier may become important when a later value is evaluated.
THE CENTRAL DIFFICULTY
A solution must establish that two elements, at different positions, satisfy the required sum.
For each active candidate, the remaining amount needed to reach the target can be determined. However, calculating that amount does not establish whether a matching element exists.
The solution must also determine whether previously examined evidence can satisfy that requirement.
Determine the complementary value required to complete the current candidate and reach the target.
Establish whether the complementary value has already been encountered at a different index.
If the required value has not appeared, determine how the current candidate can remain available for a future comparison.
THE CCF INVESTIGATION
The Correct Code Framework organizes the investigation into distinct reasoning spaces and decision responsibilities.
The Base Component establishes the identity of the solution: TwoSum.
Establish the input array, target, element positions, and the boundaries of the available evidence.
Define the required output: two distinct indices whose corresponding values sum to the target.
Determine which candidate to examine, what evidence is needed, and whether the current state supports a valid answer.
Determine whether evidence from previously examined candidates must remain available. Establish what must be preserved and how it supports later decisions.
Establish when a valid pair has been found and what result must be returned.
THE INVESTIGATION STANDARD
Two Sum introduces an important distinction: examining evidence and preserving evidence are separate responsibilities.
The Scanner determines which candidate is examined.
The Recorder preserves information that may be needed later.
The investigation must establish why both responsibilities are necessary, what information the Recorder must retain, and when that information becomes useful.
Only after the reasoning is established should the appropriate data structure, technique, algorithm, and implementation be selected.
INVESTIGATION AUTHORIZED
You have been introduced to the Two Sum problem, its available evidence, its central difficulty, and the reasoning methodology that will guide the investigation.
The investigation begins by establishing the Base Component and defining the required answer. From there, the evidence and decisions will determine what must be preserved and how it will be used.
The Scanner and Recorder must each fulfill a justified responsibility. Their relationship will be established through the evidence—not assumed before the investigation begins.