Given an integer array nums of unique elements, return all possible subsets (the power set).
The solution set must not contain duplicate subsets. Return the solution in any order.
Input: nums = [1,2,3]
Output: [[],[1],[2],[1,2],[3],[1,3],[2,3],[1,2,3]]
Input: nums = [0]
Output: [[],[0]]
1 <= nums.length <= 10-10 <= nums[i] <= 10nums are unique.The backtracking technique is one of the simplest and intuitive ways to solve this problem. The main idea is to generate all possible subsets incrementally. Here's the detailed procedure:
n is the number of elements in nums. Each element can either be included or not included, leading to 2^n possible subsets.The iterative approach builds the subsets directly using the concepts of combinatorial logic, by iteratively adding each element to existing subsets. Here's the thought process:
This approach uses the concept that each subset can be represented as a binary string of length n, where 1 indicates inclusion and 0 indicates exclusion.