Easy and Short Solution

Just read about lower_bound function and do this.

vector<int> Solution::searchRange(const vector<int> &A, int B) {
std::vector<int>::iterator low1, low2; 
vector<int> C=A;
low1 = lower_bound(C.begin(), C.end(), B);
low2 = lower_bound(C.begin(), C.end(), B+1);
int a=low1-C.begin();
int b=low2-C.begin();
if(a<b)
return {a,b-1};
else
return {-1,-1};

}

Click here to start solving coding interview questions