Whats wrong in this code...?


#1

int getfortwo(vector &B, vector &C,int num)
{ int p,q;
int j=0;
int diff=INT_MAX;
int x,y;
int finalmin=INT_MAX;
for(int i=0;i<B.size();i++)
{
for(;j<C.size();j++)
{ x=abs(max(B[i],C[j])-min(B[i],C[j]));
if(x<=diff)
{ diff=x;
p=max(B[i],C[j]);
q=min(B[i],C[j]);
y=abs(max(num,p)-min(q,num));
if(y<finalmin)
finalmin=y;
}
else
break;
}
}

return finalmin;

}
int Solution::solve(vector &A, vector &B, vector &C) {
int finaldef=INT_MAX,diff;

for(int i=0;i<A.size();i++)
{
    diff=getfortwo(B,C,A[i]);
  // cout<<diff<<"  ";
    if(diff==0)
    return 0;
    if(diff<finaldef)
    finaldef=diff;
}

// cout<<endl;
return finaldef;
}