Partial correct. Your code might be failing for larger test-cases. Whats the problem here?


#1

int Solution::threeSumClosest(vector &A, int B) {
sort(A.begin(),A.end());
int x, y, z;
long long sum,m=INT_MAX;

for(x=0;x<A.size()-2;x++){
    y=x+1;
    z=A.size()-1;
    while(y<z){
        
        if(abs(A[x]+A[y]+A[z]-B)<m){
            sum=A[x]+A[y]+A[z];
            m=abs(A[x]+A[y]+A[z]-B);
        }
        if(sum>B)
            z--;
        else if(sum<B)
            y++;
        else
            return B;
    }
}   
return sum;

}