here is my code plz tell me about my mistake
Last Test case Not passing Median of two arrays binary search
okay I will check it for the errors
int low = 0;
int high = m;
int totalLength = m+n;
while(low<=high){
int partitionX = low + (high - low)/2;
int partitionY = (totalLength + 1)/2 - partitionX;
int maxLeftX = (partitionX ==0?INT_MIN:A[partitionX-1] );
int minRightX = (partitionX == x?INT_MAX :A[partitionX]);
int maxLeftY = (partitionY ==0?INT_MIN:B[partitionY-1] );
int minRightY = (partitionY == y?INT_MAX : B[partitionY]);
if(maxLeftX<=minRightY && maxLeftY <= minRightX){
if(totalLength% 2 == 0){
return ((double)max(maxLeftX,maxLeftY) + (double)min(minRightX,minRightY))/2;
} else {
return max(maxLeftX, maxLeftY);
}
}
else if(maxLeftX>minRightY)
high = partitionX-1;
else low = partitionX+1;
}
return 0;
The code was correct the ans to be returned was int. But thank you.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.