3 sum zero

PHOTO EMBED

Sun Jun 26 2022 18:22:23 GMT+0000 (UTC)

Saved by @Ranjan_kumar #c++

vector<vector<int> > Solution::threeSum(vector<int> &A) {
    vector<int>v1;
    set<vector<int>>s;
    int n=A.size();
    sort(A.begin(),A.end());
    for(int i=0;i<n-2;i++)
    {
        int j=i+1;
        int k=n-1;
        while(j<k)
        {  
            long long sum = 0LL+A[i]+A[j]+A[k];
            if(sum==0)
            {
            v1.push_back(A[i]);
            v1.push_back(A[j]);
            v1.push_back(A[k]);
            s.insert(v1);
            v1.clear();
            }
            if(A[i]+A[j]+A[k]<0) j++;
            else k--; 
        }
        
    }
    vector<vector<int>>v2(s.begin(),s.end());
    return v2;
}
content_copyCOPY

https://www.interviewbit.com/problems/3-sum-zero/