CPP Solution Using Binary Search,first finding bitonic point then value if exist in both parts


#1
int findp(vector<int> &A, int st, int ed){
    int md=(st+ed)/2;
    if(A[md]>A[md+1] && A[md]>A[md-1])
        return md;
    if(A[md-1]<A[md] && A[md]<A[md+1])
        return findp(A,md,ed);
    return findp(A,st,md);
}
int findv1(vector<int> &A,int B, int st, int ed){
    if(st>ed) return -1;
    int md=(st+ed)/2;
    if(A[md]==B) return md;
    if(A[md]> B) return findv1(A,B,st,md-1);
    return findv1(A,B,md+1,ed);
}
int findv2(vector<int> &A,int B, int st, int ed){
    if(st>ed) return -1;
    int md=(st+ed)/2;
    if(A[md]==B) return md;
    if(A[md]> B) return findv2(A,B,md+1,ed);
    return findv2(A,B,st,md-1);
}
int Solution::solve(vector<int> &A, int B) {
    int piv=findp(A,0, A.size()-1);
    int ind=findv1(A,B,0,piv);
    if(ind!=-1) return ind;
    ind=findv2(A,B,piv+1, A.size()-1);
    return ind;
}