Find all pairs summing to X
Problem Given an array of UNIQUE non-negative integers and a target X, return all pairs of elements summing to X.
Input / Output
- Input: an int array of distinct values, and int X.
- Output: a list of pairs (each pair once; define the ordering).
Constraints
- n up to 10^5; O(n) expected.
- Values are distinct.
Example
- arr = [1,4,45,6,10,8], X = 16 -> [(6,10)].
- With X = 14 -> [(4,10), (6,8)].
asked …