AAlgoLab
ALG-E013EasyHashing

First Pair Matching a Target

Find two distinct indices i and j with i < j whose values sum to target. Return the lexicographically smallest pair [i,j], or [-1,-1] when no pair exists.

Contract

input numbers: integer[]
input target: integer
return integer[]

Constraints

  • • 0 <= length <= 500
  • • Indices are zero-based

Examples

Example 1
numbers = [2, 7, 11, 15]
target = 9
→ [0, 1]
Example 2
numbers = [3, 3]
target = 6
→ [0, 1]

5 judge tests (2 shown above). Target complexity: O(n) possible.