find pair of numbers in array that add to given sum
If you have a sorted array you can find such a pair in O(n) by moving two pointers toward the middle i = 0 j = n-1 while(i < j){ if (a[i] + a[j] == target) return (i, j); else if (a[i] + a[j] < target) i += 1; else if (a[i] + a[j] > … Read more