Python Backtracking || Explanation
Intuition\nSubset problem, think of using backtracking!\n\nWhy using dictionary instead of set or list?\nUsing List : When checking numbers in seen, it needs O(
# Intuition\nSubset problem, think of using backtracking!\n\n***Why using dictionary instead of set or list?***\nUsing List : When checking numbers in seen, it needs O(n) to check which is inefficient. \n***Then you will think about use set***. However, when you are going yo pop out the number for current dfs level and there are serveral same numbers in the subsets, there would be a problem.\n\n\n# Code\n```\nclass Solution:\n    def beautifulSubsets(self, nums: List[int], k: int) -> int:\n        self.output = 0\n        def dfs(start,seen) :\n            if start >= len(nums) :\n                return\n            for i in range(start, len(nums)) :\n                if len(seen) != 0 and seen[nums[i]-k] != 0 or seen[nums[i]+k] != 0 :\n                    continue\n                seen[nums[i]] += 1\n                self.output += 1\n                dfs(i+1, seen)\n                seen[nums[i]] -= 1\n            return\n        dfs(0, collections.defaultdict(int))\n        return self.output\n                \n                \n        \n```
['Backtracking', 'Depth-First Search', 'Python3']