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.
/**
* @param {number[]} nums
* @return {number[][]}
*/
// O(N*2^N) time to generate all subsets and then copy into output list
// O(N) space for the current subset
varsubsets=function(nums){
const allSubsets =[];
// DFS by skipping the current number or adding the current number to the current subset
constsubsetsHelper=(index, currentSubset)=>{
// If we've gone through all the nums, we'll add a clone of the current subset and return
if(index === nums.length){
allSubsets.push([...currentSubset]);
return;
}
// Try recursively creating more subsets by skipping the current number
subsetsHelper(index +1, currentSubset);
// Add the current number to the current subset and recursively try creating subsets with that current number