Arrays & two pointersEasy
Pair with target sum
pairWithSum takes a sorted array and returns the indices of two different elements that add up to target, or {} if there are none. What's wrong?
vector<int> pairWithSum(const vector<int>& a, int target) { int l = 0, r = (int)a.size() - 1; while (l <= r) { int s = a[l] + a[r]; if (s == target) return {l, r}; if (s < target) ++l; else --r; } return {};}