Learn
0 day streak

0 of 63 answered today

Clears at midnight
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 {};}

Pick with 1–4 or A–D. Once you answer, every choice is explained.