Find two indices with a target sum
Return indices [i,j] with i < j and values summing to target. Choose the smallest j, then smallest i; return [] if absent. Inputs are valid JSON and must not be modified unless the algorithm uses a local copy. This exercise probes typed data modeling, boundary handling, and algorithm selection.
Input
One JSON value: { values: number[]; target: number }. See the sample for its exact shape.
Output
One compact JSON value of type number[]. Strings include JSON quotes; arrays preserve the specified order.
Constraints
Array/string lengths are 0 to 10000 unless stated otherwise. Numbers are integers in [-1000000,1000000]; all computed results fit the safe integer range.
Example
Input
{"values":[2,7,11,15],"target":9}Output
[0,1]
Example 2 input
{"values":[1,2,3,4],"target":5}Output
[1,2]
Checks a boundary or contrasting case beyond the public examples.
Public test cases (2)
Input
{"values":[2,7,11,15],"target":9}Expected output
[0,1]
Input
{"values":[3,3],"target":6}Expected output
[0,1]
Hints (2)
- Start with the required output order and the empty-input behavior.
- Store the earliest index of each value and look up its complement
Target complexity: time O(n) · space O(n)
