I am getting correct result with my laptop's compiler, but here it's returning wrong result


#1

double Solution::findMedianSortedArrays(const vector &A, const vector &B) {

int n1=A.size();
int n2=B.size();
bool even;
if((n1+n2)%2==0)
even = true;
if(A.size()==0&&B.size()==1)
{
    return B[0];
    
}
if(B.size()==0&&A.size()==1)
{
    return A[0];
    
}
vector<int> res(n1+n2);

int i=0;int j=0;
int k=0;
while(i<n1&&j<n2)
{
    if(A[i]<=B[j])
    {
        res[k]=A[i];
        i++;
        k++;
    }
    else
    {
        res[k]=B[j];
        j++;
        k++;
    }
    
}
while(i<n1)
{
    res[k++]=A[i++];
}
while(j<n2)
{
    res[k++]=B[j++];
}
int size=res.size();
double median;
if(even)
{
    median = (res[size/2]+res[size/2-1])/2;
    
}
else
median=res[size/2];

return median;
// Do not write main() function.
// Do not read input, instead use the arguments to the function.
// Do not print the output, instead return values as specified
// Still have a doubt. Checkout www.interviewbit.com/pages/sample_codes/ for more details

}


#2

Because problem must be solved in O[log(m+n)] time complexity.