Custom input testing is giving the right answer while on submission, the same code is said to be giving a wrong one!?!


#1

int Solution::findCount(const vector &A, int B) {
int l=0;
int h=A.size()-1;
int mid;
int count = 0;
while (l<=h){
mid = floor(l+(h-l)/2);
if (A[mid]==B){
while (A[mid]==B){
count++;
mid++;
}
mid=floor(l+(h-l)/2);
mid–;
while (A[mid]==B){
count++;
mid–;
}
break;
}
else if (A[mid]<B){
l=mid+1;
}
else h=mid-1;
}
if (count ==0) return 0;
else return count;
}