Solved using lower_bound stl function


#1

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

auto x = lower_bound(A.begin(),A.end(),B);
auto y = lower_bound(A.rbegin(),A.rend(),B,greater<int>());

if(x==A.end()||y==A.rend())
    return vector<int>(2,-1);
if((*x)!=B || (*y)!=B)
    return vector<int>(2,-1);

vector<int> vec;
vec.push_back(x-A.begin());
vec.push_back(A.size()-(y-A.rbegin())-1);
return vec;

}