Extension of 2 Sum Solution, works in O(N^3)
\nclass Solution:\n    def fourSum(self, nums: List[int], target: int) -> List[List[int]]:\n        nums.sort()\n        ans = set()\n        n = len(nums)\n   
```\nclass Solution:\n    def fourSum(self, nums: List[int], target: int) -> List[List[int]]:\n        nums.sort()\n        ans = set()\n        n = len(nums)\n        for i in range(n):\n            for j in range(i+1, n):\n                # two sum problem solution\n                new_target = target - (nums[i] + nums[j])\n                start = j+1\n                end = n-1\n                while end > start:\n                    if(nums[start] + nums[end] == new_target):\n                        ans.add((nums[i], nums[j], nums[start], nums[end]))\n                        end -= 1\n                        start += 1\n                    elif nums[start] + nums[end] > new_target:\n                        end -= 1\n                    else:\n                        start += 1\n        return ans\n```
['Two Pointers', 'Python']