Simpler soln than the editorial one

int extreme(const vector &A, int x, int mode)
{
int n=A.size();
int l=0, r=n-1;

int pos=-1;
while(l<=r)
{
    int mid = (l + r)/2;
    if(A[mid] == x)
    {
        pos = x;
        
        if(mode == 0)
        r = mid-1;
        else
        l = mid+1;
    }
    else if(A[mid] > x)
    r = mid-1;
    else if(A[mid]<x)
    l = mid+1;
}

return pos;

}

vector Solution::searchRange(const vector &A, int B) {

int s = extreme(A, B, 0), e = extreme(A, B, 0);

vector<int> v;
v.push_back(s);
v.push_back(e);

return v;

}

Please, check your answer.
e = extreme(A, B, 0);
instead, e = extreme(A, B, 1);
and
pos = x;
instead, pos=mid;

Click here to start solving coding interview questions