DP, TwoSum Style Python Solution
The idea is that fourSum is just two twoSums\n1. We can treat the input like an N x N matrix of summed values \nwhere eg. nums[0][1] is nums[0] + nums[1]\nTo av
The idea is that fourSum is just two twoSums\n1. We can treat the input like an N x N matrix of summed values \nwhere eg. nums[0][1] is nums[0] + nums[1]\nTo avoid duplicate calculations we only traverse half the matrix\nstopping right before nums[i][i] because that would be a number plus itself\n\n2. Similar to twoSum, we keep track of sums we\'ve seen so far\nand find the other half we need to add up to the target\nhave = nums[r] - nums[c] basically a new two sum\nneed = target - have\nHere we\'re keeping track of the indexes in an array, with a key of their sum\n\n3. If we find it, make sure that all indexes are unique by counting a unique set\nand making sure they add to up four. Then storying in a set\n\n112 ms\nO(N^2)\n\t\t\n```\nfrom collections import defaultdict\nclass Solution:\n    def fourSum(self, nums: List[int], target: int) -> List[List[int]]:\n        # Store a dp style table of [row][col] for each two sum\n        dp = {}\n        res = set()\n        seen = defaultdict(list)\n        # 1\n        for r in range(len(nums)):\n            for c in range(r):\n                have = nums[r] + nums[c]\n                need = target - have\n                # 2\n                if need in seen:\n                    # 3\n                    for r1,c1 in seen[need]:\n                        if len({r1,c1,r,c}) == 4:\n                            res.add( tuple(sorted([nums[r1],nums[c1],nums[r],nums[c]])) ) \n                seen[have].append((r, c))\n        return res\n```
['Dynamic Programming', 'Python']