Design an algorithm to find all pairs of integers within an array which sum to a specified value.
I have tried this problem using a hash
If you don't mind spending O(M) in space, where M is the sum you are seeking, you can do this in O(N + M) time. Set sums[i] = 1 when i <= M on a single pass over N, then check (sums[i] && sums[M-i]) on a single pass over M/2.
O(M)
M
O(N + M)
sums[i] = 1
i <= M
N
(sums[i] && sums[M-i])
M/2