✅Easy C++ solution with explanation using 4 pointers!
If you\u2019re interested in coding you can join my Discord Server, link in the comment section. Also if you find any mistake please let me know. Thank you!\u27
> **If you\u2019re interested in coding you can join my Discord Server, link in the comment section. Also if you find any mistake please let me know. Thank you!\u2764\uFE0F**\n> \n\n---\n\n## Explanation:\n\n### Solution 01\n\n- First, we\u2019ll sort the array.\n- Take 4 pointers: ***i, j, left, right.***\n- Outer 2 loops for ***i & j.*** We store the remaining value to find in sum variable.\n- Then we try to calculate the ***left+right*** values & if they are equal then push all 4 values to the set.\n- If the value is less than sum then we\u2019ll increase left because array is in sorted order, else we\u2019ll decrease right.\n- **Time complexity:** O(n^3 logn).\n\n---\n\n## Code:\n\n```cpp\n//Solution 01:\n**class Solution {\npublic:\n    vector<vector<int>> fourSum(vector<int>& nums, int target) {\n        set<vector<int>>ans;\n        sort(nums.begin(), nums.end());\n        int n = nums.size();\n        int i=0, j=0, l, r;\n        while(i<n){\n            j=i+1;\n            while(j<n){\n                int sum=target-nums[i]-nums[j];\n                l=j+1; r=n-1;\n                while(l<r){\n                    int x = nums[l]+nums[r];\n                    int y = nums[l], z= nums[r] ;\n                    if(x>sum)\n                        r--;\n                    else if(x<sum)\n                        l++;\n                    else{\n                        ans.insert({nums[i],nums[j],nums[l],nums[r]});\n                        while(l<r && nums[r]==z)r--;\n                        while(l<r && nums[l]==y)l++;\n                    }\n                }j++;\n               \n            }i++;\n        }\n        vector<vector<int>>res(ans.begin(),ans.end());\n        return res;\n    }\n};**\n```\n\n---\n\n> **Please upvote this solution**\n>
['C', 'C++']