Example 1 · empty
- Arguments
- values
[]
target0
- Expected return
[]
Test data
- Input
{"values":[],"target":0}- Expected output
[]
func PairSumIndices(values []int, target int) []intExamples use {"values": [...], "target": ...}.
The runner calls your functions directly; you do not need to parse JSON.
[]
0
[]
{"values":[],"target":0}[]
[ 8, 3, 6, 1 ]
9
[ 1, 2 ]
{"values":[8,3,6,1],"target":9}[1,2]
[ 2, 2, 3 ]
5
[ 0, 2 ]
{"values":[2,2,3],"target":5}[0,2]
[ 1, 4, 9 ]
8
[]
{"values":[1,4,9],"target":8}[]
When checking right index j, the map contains only positions before j, preventing reuse of one position. Returning at the first matching j minimizes the right index. Retaining the earliest occurrence of each complement also minimizes the left index among pairs with that same right endpoint.
Expected O(n) time and O(n) auxiliary space for n values. Do not sort or modify the input; sorting would also lose the required original-position ordering unless additional work restored it.
Checking execution availability…
View inputs and expected outputs. Examples do not run your code.