Stl and custom bs, short and best open for suggestion c++

int bs1(const vector<int> &a,int x, int y, int val){
    if(x<y){
        int mid=(x+y)/2;
        if(a[mid]==val){
            int temp=bs1(a,x,mid,val);
            if(temp==-1) return mid;
            return temp;
        }
        if(val>a[mid]){
           return bs1(a,mid+1,y,val);
        }else{
            return bs1(a,x,mid,val);
        }
    }
    return -1;
}
int bs2(const vector<int> &a,int x, int y, int val){
    if(x<y){
        int mid=(x+y)/2;
        if(a[mid]==val){
            int temp=bs2(a,mid+1,y,val);
            if(temp==-1) return mid;
            return temp;
        }
        if(val>a[mid]){
           return bs2(a,mid+1,y,val);
        }else{
            return bs2(a,x,mid,val);
        }
    }
    return -1;
}
vector<int> Solution::searchRange(const vector<int> &a, int b) {
    // auto pos1=lower_bound(a.begin(),a.end(),b);
    // if(*pos1 != b) return {-1,-1};
    // auto pos2=upper_bound(a.begin(),a.end(),b);
    // return {(pos1-a.begin()),(pos2-a.begin()-1)};
    int pos1=bs1(a,0,a.size(),b);
    int pos2=bs2(a,0,a.size(),b);
    return {pos1,pos2};
}
Click here to start solving coding interview questions