Brute Force ,Optimised, Hashset Approach
Brute Force--->O(N^4)--->[TLE]\n\nclass Solution:\n    def fourSum(self, nums: List[int], target: int) -> List[List[int]]:\n        ans=[]\n        n=len(nums)\
# Brute Force--->O(N^4)--->[TLE]\n```\nclass Solution:\n    def fourSum(self, nums: List[int], target: int) -> List[List[int]]:\n        ans=[]\n        n=len(nums)\n        for i in range(n-3):\n            for j in range(i+1,n-2):\n                for k in range(j+1,n-1):\n                    for l in range(k+1,n):\n                        temp=nums[i]+nums[j]+nums[k]+nums[l]\n                        sorted_num=sorted([nums[i],nums[j],nums[k],nums[l]])\n                        if temp==target and sorted_num not in ans:\n                            ans.append(sorted_num)\n        return ans\n```\n# Optimised Approach-->Two Pointers Appraoch ----> O(N^3)---->[Accepted]\n```\nclass Solution:\n    def fourSum(self, nums: List[int], target: int) -> List[List[int]]:\n        ans=[]\n        n=len(nums)\n        nums.sort()\n        for i in range(n-3):\n            for j in range(i+1,n-2):\n                k=j+1\n                l=n-1\n                while k<l:\n                    temp=nums[i]+nums[j]+nums[k]+nums[l]\n                    sorted_num=sorted([nums[i],nums[j],nums[k],nums[l]])\n                    if temp==target and sorted_num not in ans:\n                        ans.append(sorted_num)\n                    elif temp>target:\n                        l-=1\n                    else:\n                        k+=1\n        return ans\n ```\n # Using Hashset----->O(N^3)---->[Accepted]\n ```\n class Solution:\n    def fourSum(self, nums: List[int], target: int) -> List[List[int]]:\n        ans=set()\n        n=len(nums)\n        nums.sort()\n        for i in range(n-3):\n            for j in range(i+1,n-2):\n                k=j+1\n                l=n-1\n                while k<l:\n                    temp=nums[i]+nums[j]+nums[k]+nums[l]\n                    if temp==target:\n                        ans.add((nums[i],nums[j],nums[k],nums[l]))\n                        k+=1\n                    elif temp>target:\n                        l-=1\n                    else:\n                        k+=1\n        return list(ans)\n ```\n # please upvote me it would encourage me alot\n\n
[]